Toon posts:

[Excel 2003] Vba code om gedeelte string te zien

Pagina: 1
Acties:

Verwijderd

Topicstarter
Zou iemand mij kunnen helpen om een "contains" of "isin" te kunnen maken (of wellicht is het er al). De bedoeling is dat ik kan kijken of String v1 zit in String v2. (bijvoorbeeld v1 = "re" v2="fred" dan moet er true uitkomen)
Een zoekterm op google die niet alleen maar onzin oplevert mag natuurlijk ook :)

Ik wil het gebruiken om te testen of een werkbladnaam "tijdelijk" in zijn naam draagt, om hem daarna te verwijderen.

  • BtM909
  • Registratie: Juni 2000
  • Niet online

BtM909

Watch out Guys...

Zoek eens in de VBA help naar Instr ;)

Er staan zelfs voorbeelden bij hoe het werk

Visual Basic:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
' Taal VB gekozen vanwege kleurtjes, het is wel degelijk VBA

Dim SearchString, SearchChar, MyPos

SearchString ="XXpXXpXXPXXP"    ' String to search in.
SearchChar = "P"                ' Search for "P".

' A textual comparison starting at position 4. Returns 6.
MyPos = Instr(4, SearchString, SearchChar, 1)    

' A binary comparison starting at position 1. Returns 9.
MyPos = Instr(1, SearchString, SearchChar, 0)

' Comparison is binary by default (last argument is omitted).
MyPos = Instr(SearchString, SearchChar)    ' Returns 9.

MyPos = Instr(1, SearchString, "W")        ' Returns 0.

[ Voor 25% gewijzigd door BtM909 op 08-03-2005 10:36 ]

Ace of Base vs Charli XCX - All That She Boom Claps (RMT) | Clean Bandit vs Galantis - I'd Rather Be You (RMT)
You've moved up on my notch-list. You have 1 notch
I have a black belt in Kung Flu.


Verwijderd

Topicstarter
thnx das de expressie die ik zocht. Slotje :P