Share via

Excel VBA Code not compiling

Anonymous
2024-08-16T18:35:43+00:00

I am trying to run a loop. I've tried For...Next, and Do While....Loop. Although the For and Do While lines are obviously in the code, Excel says compiler error, no For (or Do While) found.

My Code:

Option Explicit

Sub DelEmptyRows()

Dim i As Integer 

Do While Cells(i, 1) <> 515 

    If Cells(i, 1) = "" Then 

        Rows(i).Select 

        Selection.Delete shift:=xlUp 

        i = i - 1 

    End 

    i = i + 1 

Loop 

End Sub

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2024-08-16T19:00:37+00:00

You must end the If ... Then block with End If instead of just End:

Sub DelEmptyRows()
    Dim i As Integer
    Do While Cells(i, 1) <> 515
        If Cells(i, 1) = "" Then
            Rows(i).Select
            Selection.Delete shift:=xlUp
            i = i - 1
        End If
        i = i + 1
    Loop
End Sub

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2024-08-16T19:52:29+00:00

    duh.

    Thank you so much

    Was this answer helpful?

    0 comments No comments