我有以下代码来隐藏定义范围内的值为零的列。不知道为什么我总是得到“Next without For”错误。有人可以帮忙吗?感谢。
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
答案 0 :(得分:1)
您错过了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