Hi All, first time poster here, I hope i get this right. Thanks in advance for any help! Running Office 365 desktop apps.
I am calling the sub below, as part of a loop, and it only performs the delete rows part when I step through it using F8. When i run the entire code where it calls this, it seemingly ignores this step. I am thinking it has something to do with the way this is written.
I only want to retain records that are a value of 5 and under, in column I. Below is the code in question.
Private Sub DeleteRowsOver5()
With Sheets("Worksheet")
Sheets("Worksheet").Range("i2").Value = 1
Sheets("Worksheet").Range("i3").Value = "=I2+1"
Sheets("Worksheet").Range("I3:I" & Cells(Rows.Count, 8).End(xlUp).Row).FillDown
Dim r As Long
Dim lastrow As Long
lastrow = Cells(Rows.Count, "I").End(xlUp).Row
For r = lastrow To 1 Step -1
If Cells(r, "I") > 5 Then
Rows(r).Delete
End If
Next r
End With
End Sub
I am calling the sub below, as part of a loop, and it only performs the delete rows part when I step through it using F8. When i run the entire code where it calls this, it seemingly ignores this step. I am thinking it has something to do with the way this is written.
I only want to retain records that are a value of 5 and under, in column I. Below is the code in question.
Private Sub DeleteRowsOver5()
With Sheets("Worksheet")
Sheets("Worksheet").Range("i2").Value = 1
Sheets("Worksheet").Range("i3").Value = "=I2+1"
Sheets("Worksheet").Range("I3:I" & Cells(Rows.Count, 8).End(xlUp).Row).FillDown
Dim r As Long
Dim lastrow As Long
lastrow = Cells(Rows.Count, "I").End(xlUp).Row
For r = lastrow To 1 Step -1
If Cells(r, "I") > 5 Then
Rows(r).Delete
End If
Next r
End With
End Sub