由于某种原因,我无法获取以下代码来遍历工作簿中的所有工作表。当我执行代码时,它会删除我所在的任何工作表上的隐藏列,但它不会遍历工作簿中的所有工作表。有人可以帮忙吗?谢谢!
Sub delete_hidden_columns()
Dim ws As Worksheet
Dim i As Integer
For Each ws In ThisWorkbook.Worksheets
For i = 256 To 1 Step -1
If Columns(i).EntireColumn.Hidden = True Then Columns(i).EntireColumn.Delete Else
Next
Next ws
End Sub
答案 0 :(得分:0)
您缺少“结束如果”声明。
也把ws。在你的专栏前面
Dim ws As Worksheet
Dim i As Integer
For Each ws In ThisWorkbook.Worksheets
For i = 256 To 1 Step -1
If ws.Columns(i).EntireColumn.Hidden Then
ws.Columns(i).EntireColumn.Delete
End If
Next
Next ws
Set ws = Nothing