I'm am very new to vba and I have a excel sheet that has roughly 200 names, agent id and their role. I am trying to write a vba code to search for a Name via input box and paste All occurance of that name at the top of the sheet starting at row 3 and then insert a black line between the search data and existing data. Example I input "Jen" and copy every row that "Jen" occurs and inserts a row at row 3 and inserts the copied data moving existing data down. I have included what i have so far.I have pieced it together from codes that i have found online. I don't think it is totally correct. As my cancel button doesn't work and if the person searching leave it empty it still tries to copy data. Any help would be grateful.
Code:
Dim LSearchValue As String
Dim RefCount As Integer
Application.ScreenUpdating = False
LSearchValue = InputBox("Who do you want.", "Enter name") & "*"
Rows("3:3").Select
Selection.Insert
RefCount = Application.WorksheetFunction.CountIf(Worksheets("agent").Range("A:C"), LSearchValue) - 1
Range("A2").Activate
For Counter = 0 To RefCount Step 1
With Columns("A:C").Find(What:=LSearchValue, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
Rows("3:3").Select
Selection.Insert
.EntireRow.Copy Destination:=Worksheets("Agent").Range("a3")
.Activate
End With
Next
Application.ScreenUpdating = True
Application.Goto Reference:=Range("a1"), Scroll:=True
Bookmarks