I am developing a macro that allows a user to enter area codes into Column A of a "Search" and state abbreviations into column "B". The macro then searches a table of data (Results), looking for either criteria and when it finds a match, it copies the row and pastes it to a different tab (AcctDetailGeo)
I want people to be able to search and return results if they search for area codes or states (or both). Currently, my code will only return results if Column A has a value or if Columns A and B have values. If Column A is empty but Column B has values, it does not work. Can someone take a peak at this and tell me what I need to change in order for the macro to look at Column B even if Column A has no value
Thanks in advance for the help
CODE
Dim rcnt1 As Long, rcnt2 As Long, cnt As Long
rcnt1 = Sheets("Results").Range("A" & Rows.Count).End(xlUp).Row
rcnt2 = Sheets("Search").Range("A" & Rows.Count).End(xlUp).Row
cnt = Sheets("AcctDetailGeo").Range("A" & Rows.Count).End(xlUp).Row
For j = 2 To rcnt2
For i = 2 To rcnt1
If (Sheets("Search").Range("A" & j).Value = Sheets("Results").Range("L" & i).Value) Or (Sheets("Search").Range("B" & j).Value = Sheets("Results").Range("M" & i).Value) Then
cnt = cnt + 1
Sheets("Results").Rows(i & ":" & i).Copy (Sheets("AcctDetailGeo").Range("A" & cnt))
End If
Next
Next
Bookmarks