Sorry if this is simple, this is my first time trying VBA.
So I want this macro to get rid of rows I don't need, and for every entity it has a total field (about every 20 records or so) and I made this script:
Dim i As Integer
Dim LastRow As Integer
LastRow = Range("A65536").End(xlUp).Row
For i = 3 To LastRow
If Range("C" & i) = "Result" Then
Rows(i & ":" & i).Select
Selection.Delete Shift:=x1Up
End If
Next
And that worked perfectly! Then I tried to a similar thing.. I tried to go through each row (record) in a data set and then if a certain field does not contain the string "INVOICE" then I don't need that row and I can delete it. So I just added into my current loop (why loop twice?) So now it looks like this:
Dim i As Integer
Dim LastRow As Integer
LastRow = Range("A65536").End(xlUp).Row
For i = 3 To LastRow
If Range("C" & i) = "Result" Then
Rows(i & ":" & i).Select
Selection.Delete Shift:=x1Up
End If
If Not InStr(1, Range("Q" & i), "INVOICE") Then
Rows(i & ":" & i).Select
Selection.Delete Shift:=x1Up
End If
Next
That second bit as far as I can tell just randomly starts deleting rows with no rhyme or reason. Rows where the Q field doesn't contain invoice sometimes stay sometimes go, and same if it does contain invoice. Any idea what I'm doing wrong?