Decrement in for each loop
17,595
No.
You have to use a For...Next
loop and step backwards:
Dim i As Long
For i = rng.Rows.Count To 1 Step -1
Set row = rng.Rows(i)
If WorksheetFunction.CountA(row) = 0 Then
row.EntireRow.Delete
'Previous row
End If
Next i
Author by
czarek zmuda
Updated on June 15, 2022Comments
-
czarek zmuda almost 2 years
Is it possible to decrement in For each loop in VBA for Excel?
I have code like this:
Sub Makro1() Dim rng As Range Dim row As Range Dim cell As Range Set rng = Range("B1:F18") For Each row In rng.Rows If WorksheetFunction.CountA(row) = 0 Then row.EntireRow.Delete 'Previous row End If Next row End Sub
And I want to step back in commented statement. Is it possible?