I am trying to loop through cells in column A and find a specific string of text. The strings of text are like this:
tag:(1001)[EX==]
tag:(1002)[EX==]
tag:(1003)[EX==]
etc...
I want to use wildcards like this:
"tag:(1###)[EX??]"
Where the 3 ###'s are any 3 numbers and the 2 ?? are any 2 single characters.
However, I also want the [EX??] to be in an array like this:
ArrTagSuffix = Array("[EX??]", "[IN??]", "[EXLW]")
So... the wild card string will look something like this:
"tag:(1###)" & ArrTagSuffix
In addition, I want the "1" in "tag:(1###)" to be something like "i" so that I can index it like this:
"tag:(" & i & "###)" & ArrTagSuffix
My first problem is this format with the wildcards doesn't seem to be working. My second problem revolves around trying to figure out the looping/searching.
Basically, assuming "i" can be 1 To 6 and ArrTagSuffix will have 3 different strings. There can ultimately be 18 different combinations of "i's" and ArrTagSuffix. I want to search column A... if it finds no matches... do nothing... but if it finds a match... copy all matching cells onto a new sheet. But I need it to copy it to the same cell as it was found... So... for example... If a match is found in cell A23... it needs to be copied to cell A23 of the new sheet.
So... for example... If Sheet1... Column A has:
Blank cell
Blank cell
tag:(1001)[EX==]
Blank cell
tag:(1002)[EX==]
tag:(1003)[EX==]
Blank cell
tag:(3001)[EX==]
tag:(3002)[EX==]
tag:(3003)[EX==]
tag:(6001)[IN==]
Blank cell
tag:(6002)[IN==]
tag:(6003)[IN==]
tag:(1001)[EXLW]
Blank cell
tag:(1002)[EXLW]
tag:(1003)[EXLW]
The program would find 4 matches:
"1" and an "[EX??]"
"3" and an "[EX??]"
"6" and an "[IN??]"
"1" and an "[EXLW]"
So... it would copy the matches of column A to the appropriate cells of 4 new sheets.
Originally, I had a simpler task where i only needed to find the word "tag" and I had this code which worked:
With ActiveSheet
Set criteriarange = Range("A1:A" & LShtRow)
For Each criteriacell In criteriarange
If Not criteriacell.Value Like "tag:*" Then
criteriacell.ClearContents
End If
Next criteriacell
End With
So I began modifying this to try to accomplish this task... but like I said above... I wasn't even able to get the wildcard portion to work correctly... let alone the loops... Here is where I am at:
With ActiveSheet
Set criteriarange = Range("A1:A" & LShtRow)
For Each criteriacell In criteriarange
If Not criteriacell.Value Like "tag:(" & i & "###)" & ArrTagSuffix Then
criteriacell.ClearContents
End If
Next criteriacell
End With
Immediately I realized that it didn't know what to do with the "i" So I changed the "i" to a "1" temporarily to see if I got any matches:
With ActiveSheet
Set criteriarange = Range("A1:A" & LShtRow)
For Each criteriacell In criteriarange
If Not criteriacell.Value Like "tag:(" & "1" & "###)" & ArrTagSuffix Then
criteriacell.ClearContents
End If
Next criteriacell
End With
but I didn't which indicated to me that my format for the wild cards was not correct. To really simplify things... I tried:
With ActiveSheet
Set criteriarange = Range("A1:A" & LShtRow)
For Each criteriacell In criteriarange
If Not criteriacell.Value Like "tag:(1###)" & ArrTagSuffix Then
criteriacell.ClearContents
End If
Next criteriacell
End With
Still doesn't work and I tried this:
With ActiveSheet
Set criteriarange = Range("A1:A" & LShtRow)
For Each criteriacell In criteriarange
If Not criteriacell.Value Like "tag:(1???)" & ArrTagSuffix Then
criteriacell.ClearContents
End If
Next criteriacell
End With
Still doesn't work... and by doesn't work, I mean it clears the contents of the cells even if they match the format I am searching for.