I am new to VBA and am in need of some help.
My goal is to copy rows to a new sheet, based on a search from a set list.
I found a macro via a google search earlier and tried to modify it to my needs, but I'm not competent enough yet.
I'm getting this error: Run-time error '1004'
Thank you.
My goal is to copy rows to a new sheet, based on a search from a set list.
I found a macro via a google search earlier and tried to modify it to my needs, but I'm not competent enough yet.
Code:
Sub Search()
'If value in column B = Matches anything in column G, copy entire row to Sheet2
Dim searchTerm As String
For I = 1 To 1130
searchTerm = ActiveSheet.Range("G" & I).Text
If ActiveSheet.Range("B" & CStr(LSearchColumn)).Value = searchTerm Then
'Select row in Sheet1 to copy
Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
Selection.Copy
'Paste row into Sheet2 in next row
Sheets("Sheet2").Select
Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
ActiveSheet.Paste
'Move counter to next row
LCopyToRow = LCopyToRow + 1
'Go back to Sheet1 to continue searching
Sheets("Sheet1").Select
End If
Next I
End Sub
I'm getting this error: Run-time error '1004'
Thank you.