Hi Guys,
I have a macro to search for a string and copy its row to another sheet but it does not search through all the columns as it leaves some cells with search string without copying its rows. Please see below and attached.
I have a macro to search for a string and copy its row to another sheet but it does not search through all the columns as it leaves some cells with search string without copying its rows. Please see below and attached.
Code:
Dim myWord$
myWord = InputBox("What key word to copy rows", "Enter your word")
If myWord = "" Then Exit Sub
Application.ScreenUpdating = False
Dim xRow&, NextRow&, LastRow&
NextRow = 2
LastRow = Cells.Find(What:="*", After:=Range("L1"), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Column
For xRow = 1 To LastRow
If WorksheetFunction.CountIf(Rows(xRow), "*" & myWord & "*") > 0 Then
Rows(x[U]Row).Copy Sheets("Search Result").Rows(NextRow)
NextRow = NextRow + 1
End If
Next xRow
Application.ScreenUpdating = True
MsgBox "Macro is complete, " & NextRow - 2 & " rows containing" & vbCrLf & _
"''" & myWord & "''" & " were copied to Search Result Sheet.", 64, "Done"
End Sub