我正在尝试选择多个工作表,然后一次取消隐藏所有列。我正在使用案例声明。
我的脚本已成功执行,但是它跳过了我想做的事情"Columns.EntireColumn.Hidden=False
。
我确定我错过了几分钟,任何帮助将不胜感激!我通过多行内容撰写了该案例,并猜测这可能与问题有关。下面是我的代码:
For Each ws In Worksheets
Select Case ws.Name
Case "Customer Service", "Document Production & Status", "Employment", _
"Family & Business", "Humanitarian", "Refugee, Asylum, & DACA", _
"NSC", "I-102", "I-824", "I-121 AP", "I-131 TD", "I-765", "I-485 EB", _
"I-104", "I-140 Prem", "I-601A", "I-129", "I-129 Prem", "I-129F", _
"I-130 IR", "I-130 All Other", "I-539", "I-360", "I-918", "I-192", _
"I-821 TPS", "Wvrs (I-212)", "Wvrs (I-601)", "I-131 D", "I-485 Asy", _
"I-485 Ref", "I-730", "I-765 D", "I-765 D Renewal", "I-765 D Renewal ELIS", _
"I-821 D", "I-821 D Renewal", "I-821 D Renewal ELIS", "I-751", "N-565"
Columns.EntireColumn.Hidden = False
End Select
Next
答案 0 :(得分:0)
这应该有帮助:
Sub HideColumns()
Dim wb As Workbook, ws As Worksheet, shts As Variant, Check As Variant
Set wb = ThisWorkbook
'store all your worksheet names on this array
shts = Array("Customer Service", "Document Production & Status", "Employment", _
"Family & Business", "Humanitarian", "Refugee, Asylum, & DACA", _
"NSC", "I-102", "I-824", "I-121 AP", "I-131 TD", "I-765", "I-485 EB", _
"I-104", "I-140 Prem", "I-601A", "I-129", "I-129 Prem", "I-129F", _
"I-130 IR", "I-130 All Other", "I-539", "I-360", "I-918", "I-192", _
"I-821 TPS", "Wvrs (I-212)", "Wvrs (I-601)", "I-131 D", "I-485 Asy", _
"I-485 Ref", "I-730", "I-765 D", "I-765 D Renewal", "I-765 D Renewal ELIS", _
"I-821 D", "I-821 D Renewal", "I-821 D Renewal ELIS", "I-751", "N-565")
For Each ws In wb.Worksheets
Check = 0
Check = Application.Match(ws.Name, shts, 0) 'application won't raise an error if can't find the result, instead will give check an error value
If Not IsError(Check) Then ws.Columns.EntireColumn.Hidden = False
Next ws
End Sub