Hi, I'm new to writing macros in Excel and I'm trying to write on that iterates through the rows of an excel file until it matches a string, and delete all the rows before the string. Below is my code:
Sub DeleteRows()
LR = Cells(Rows.Count, "A").End(xlUp).Row
Dim i As Integer
i = 1
Do While i < LR
If StrComp(CStr(Worksheets("Sheet1").Range(i).Value), "Items in search results") = 0 Then
Rows(1 & ":" & i).EntireRow.Delete
Else
i = i + 1
End If
i = LR
Loop
End Sub
However, when I run the macro on my test spreadsheet, I get an error on the If statement saying there is an 'object defined error'. What does this mean? Thanks!
Bookmarks