Ding Li
Ding Li

Reputation: 1

Macro Error - Next without For

I have the following code to hide the columns with zero value in it for the defined range. Not sure why I always get the "Next without For" error. Can anyone help? Thanks.

Sub hidecolumns1()

Dim rRange As Range
Dim rCell As Range

Set rRange = Worksheets("Income Statement - Rollover").Range("B54:KZ54").Cells
'Set rRange = Selection.Cells

    For Each rCell In rRange
        If rCell.Text <> "" Then
        rCell.Columns.EntireColumn.Hidden = True
    Next rCell

End Sub

Upvotes: 0

Views: 36

Answers (1)

mechanical_meat
mechanical_meat

Reputation: 169384

You're missing an end if:

Sub hidecolumns1()

Dim rRange As Range
Dim rCell As Range

Set rRange = Worksheets("Income Statement - Rollover").Range("B54:KZ54").Cells
'Set rRange = Selection.Cells

    For Each rCell In rRange
        If rCell.Text <> "" Then
            rCell.Columns.EntireColumn.Hidden = True
        End If '<---
    Next rCell

End Sub

Upvotes: 1

Related Questions