I am trying to get this macro to search through column A to find all entries with a certain name (user input) and then copying and pasting each matching row to a different sheet in the work book. Here is what I have so far:
Option Explicit
Sub clear()
Sheets("Table").Select
Columns("A:S").EntireColumn.ClearContents
Sheets("Summary").Select
End Sub
Sub SearchForString()
Dim LSearchRow As String
Dim LCopyToRow As Long
Dim userinput As String
userinput = InputBox(Prompt:="Enter name here.", _
Title:="ENTER NAME", Default:="Name here")
LSearchRow = 2
LCopyToRow = 1
While Len(Range("A" & CStr(LSearchRow)).Value) > 0
If Range("A" & CStr(LSearchRow)).Value = userinput Then
Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
Selection.Copy
Sheets("Summary").Select
Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
ActiveSheet.Paste
LCopyToRow = LCopyToRow + 1
Sheets("Summary").Select
End If
LSearchRow = LSearchRow + 1
Wend
Application.CutCopyMode = False
Range("b2").Select
MsgBox "All matching data has been copied."
Exit Sub
End Sub
This seems to do what I am intending, however, it only returns the very first match and does not search throughout the entire column. The sheet with the data is named "Table" and the sheet I am copying too is "Summary." Any help would be much appreciated!
Here is an example of the data I am using:
Tyler Barto 5 8. 7.50 .50 .50 7. 6.50 0 1326 0 222 1296. 521 204.00 80.
Jake Parker 6 5. 1.70 .50 .50 4. .70 0 264 0 0 274. 137 377. 196. 61.
Rob Carlton 7 5. 4. .50 .50 4. 3. 0 885 0 248 859.3 0 290 271. 89.
Bookmarks