Array Indexing Troubles

dw1011

New Member
Joined
Sep 18, 2014
Messages
6
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!
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
I have changed the following to eliminate the possibility of overwriting... That still didn't seem to correct the issue. The closest thing I'm seeing to a pattern witht he rows that should be getting flagged but aren't, is that usually the keyword is the first word in the column most of the time...

Else
Cells(rowNum, 17) = "-"

To

ElseIf Cells(rowNum,17) <> "Nickel" Then
Cells(rowNum, 17) = "-"


Thanks
 
Upvote 0

Forum statistics

Threads
1,216,134
Messages
6,129,070
Members
449,485
Latest member
greggy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top