Hi all,
I'm fairly new to VBA and recently i was working on a file with a VBA code as per below which deletes rows that has zero in column 'I'.
Dim i As Long, n As Long
Dim rg As Range
Application.ScreenUpdating = False
With ActiveSheet
Set rg = Intersect(.UsedRange, .Columns("I"))
n = rg.Rows.Count
For i = n To 8 Step -1
If Not IsError(rg.Cells(i, 1).Value) Then
If rg.Cells(i, 1).Value = 0 Then rg.Rows(i).EntireRow.Delete
End If
Next
End With
I was having trouble understanding this whole sequence so i did a test where i input a single row in column 'J' to zero. Then i changed the above Columns("I") to Columns ("J") and it then deleted a whole bunch of rows which are not supposed to be deleted.
Can someone assist me with how the vba code above works? Many thanks
I'm fairly new to VBA and recently i was working on a file with a VBA code as per below which deletes rows that has zero in column 'I'.
Dim i As Long, n As Long
Dim rg As Range
Application.ScreenUpdating = False
With ActiveSheet
Set rg = Intersect(.UsedRange, .Columns("I"))
n = rg.Rows.Count
For i = n To 8 Step -1
If Not IsError(rg.Cells(i, 1).Value) Then
If rg.Cells(i, 1).Value = 0 Then rg.Rows(i).EntireRow.Delete
End If
Next
End With
I was having trouble understanding this whole sequence so i did a test where i input a single row in column 'J' to zero. Then i changed the above Columns("I") to Columns ("J") and it then deleted a whole bunch of rows which are not supposed to be deleted.
Can someone assist me with how the vba code above works? Many thanks