Hello....I'm trying to create a macro that will scan a selected column for a value, and if it finds a cell with the value I am looking for, it will copy the entire row. For example, I am looking for cells with 3051 and H2.
1. 3051AABBSSH2
2. 3051SJDIUS
3. 3051SJHEISH3
4. 3051SJSJSH2
5. 3051SSJJJH2
After running the macro, it should have rows 1, 4 and 5 copied. I was trying to use the following code:
Public Sub seekAndFilter()
Dim rng As Range
For Each rng In Selection
If ((InStr(1, rng.Value, "3051") <> 0 And InStr(1, rng.Value, "H2") <> 0)) Then
rng.EntireRow.Copy
End If
Next
End Sub
The issue I run into is that it only will copy the last row that it finds with 3051 and H2, so in the above example, it copies 3051SSJJJH2 3 times. I am very new to making macros, so I'm sure it must be a dumb error I made. Any help would be much appreciated!
Bookmarks