PDA

View Full Version : [SOLVED:] Wildcards for not contain



chungtinhlak
01-14-2009, 10:31 AM
I search through the forum for wildcards, I figure out how to use wildcards in contains would be .value like "*text*"

what about does not contain. I tried this but it does not work.



Sub testttt()
If Range("A2").Value <> "*th*" Then
MsgBox ("not alike")
End If
End Sub

lucas
01-14-2009, 10:36 AM
This searches column D for any word containing the string labor:


Public Sub DeleteRowsWithLabor()
Const TEST_COLUMN As String = "D" '<=== change to suit
Dim i As Long
Dim iLastRow As Long
With ActiveSheet
'change next line to determine which column to find last row in.
iLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
' iLastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
For i = iLastRow To 1 Step -1
If .Cells(i, TEST_COLUMN).Value Like "*Labor*" Then
Rows(i).Delete
End If
Next i
End With
End Sub

If you use Option compare text right below your option explicit it will be cap insensitive.

lucas
01-14-2009, 10:39 AM
Therefore, change this line if you want the ones that do not contain labor:


If Not .Cells(i, TEST_COLUMN).Value Like "*Labor*" Then

chungtinhlak
01-14-2009, 10:46 AM
like is for contain, and you use if not contain labor, is there a formal way to test if something doesn't contain a string with wild cards?

chungtinhlak
01-14-2009, 10:52 AM
n/m, it makes sense, sorry. thank you for your help