I'm trying to search 2 different columns containing strings for keywords, which I have put in an array. I'm also searching a couple of other columns for some specific numbers. If conditions are met, I want to flag a cell with an "x", if conditions are not met, I want to mark it with an "-".
The macro seems to work fine through the first iteration, but after the 1st index, the keywords quit marking cells that meet the criteria with an "x". I've stepped through this several times and I can't figure out where it is going wrong. Does anyone see where I am going wrong, or any tips to help me get this working correctly? I appreciate your help!
Sub textFilter()
Dim searchCol1 As Variant
Dim searchCol2 As Variant
Dim rowNum As Integer
Dim index As Integer
Dim keyword(1 To 5) As String
keyword(1) = "plat"
keyword(2) = "nick"
keyword(3) = "cycl"
keyword(4) = "class"
keyword(5) = "plt"
For index = 1 To 5
rowNum = 5
Do Until IsEmpty(Cells(rowNum, 1))
If Cells(rowNum, 17) <> "X" Then
searchCol1 = Cells(rowNum, 9)
searchCol2 = Cells(rowNum, 12)
'Search Column 1 for keywords
If InStr(1, searchCol1, keyword(index)) > 0 Then
Cells(rowNum, 17) = "X"
'Search Column 2 for keywords
ElseIf InStr(1, searchCol2, keyword(index)) > 0 Then
Cells(rowNum, 17) = "X"
' Search Number Column 1
ElseIf Cells(rowNum, 13) >= 140 And Cells(rowNum, 13) <= 209 Then
Cells(rowNum, 17) = "X"
'Search Number Column 2
ElseIf Cells(rowNum, 11) = 140 Then
Cells(rowNum, 17) = "X"
Else
Cells(rowNum, 17) = "-"
End If
rowNum = rowNum + 1
Loop
Next index
End Sub
Thanks!
The macro seems to work fine through the first iteration, but after the 1st index, the keywords quit marking cells that meet the criteria with an "x". I've stepped through this several times and I can't figure out where it is going wrong. Does anyone see where I am going wrong, or any tips to help me get this working correctly? I appreciate your help!
Sub textFilter()
Dim searchCol1 As Variant
Dim searchCol2 As Variant
Dim rowNum As Integer
Dim index As Integer
Dim keyword(1 To 5) As String
keyword(1) = "plat"
keyword(2) = "nick"
keyword(3) = "cycl"
keyword(4) = "class"
keyword(5) = "plt"
For index = 1 To 5
rowNum = 5
Do Until IsEmpty(Cells(rowNum, 1))
If Cells(rowNum, 17) <> "X" Then
searchCol1 = Cells(rowNum, 9)
searchCol2 = Cells(rowNum, 12)
'Search Column 1 for keywords
If InStr(1, searchCol1, keyword(index)) > 0 Then
Cells(rowNum, 17) = "X"
'Search Column 2 for keywords
ElseIf InStr(1, searchCol2, keyword(index)) > 0 Then
Cells(rowNum, 17) = "X"
' Search Number Column 1
ElseIf Cells(rowNum, 13) >= 140 And Cells(rowNum, 13) <= 209 Then
Cells(rowNum, 17) = "X"
'Search Number Column 2
ElseIf Cells(rowNum, 11) = 140 Then
Cells(rowNum, 17) = "X"
Else
Cells(rowNum, 17) = "-"
End If
rowNum = rowNum + 1
Loop
Next index
End Sub
Thanks!