Hello,
I am an intermediate VBA user. I have made a marco that will search an excel worksheet for a manually defined text string and paste ALL rows corresponding to cells containing the text string into a new sheet. It works great except that I never stops. I cannot seem to get the loop to end. Please help.
Sub test()
Dim lngNextRow As Long
Dim strMyString As String
Sheets("ILP YTD").Activate
Range("H9").Activate
strMyString = InputBox("Enter the number you wish to find")
Do
Cells.Find(What:=strMyString, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext).Activate
ActiveCell.EntireRow.Copy
Sheets("Search").Select
lngNextRow = Range("A" & Rows.Count).End(xlUp).Row + 1
Range("A" & lngNextRow).PasteSpecial
Sheets("ILP YTD").Activate
Loop Until IsEmpty(ActiveCell.Offset(1, 0))
End Sub
I am an intermediate VBA user. I have made a marco that will search an excel worksheet for a manually defined text string and paste ALL rows corresponding to cells containing the text string into a new sheet. It works great except that I never stops. I cannot seem to get the loop to end. Please help.
Sub test()
Dim lngNextRow As Long
Dim strMyString As String
Sheets("ILP YTD").Activate
Range("H9").Activate
strMyString = InputBox("Enter the number you wish to find")
Do
Cells.Find(What:=strMyString, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext).Activate
ActiveCell.EntireRow.Copy
Sheets("Search").Select
lngNextRow = Range("A" & Rows.Count).End(xlUp).Row + 1
Range("A" & lngNextRow).PasteSpecial
Sheets("ILP YTD").Activate
Loop Until IsEmpty(ActiveCell.Offset(1, 0))
End Sub