【发布时间】:2022-11-01 23:25:51
【问题描述】:
我想制作一个复选框,调用一个宏来隐藏和取消隐藏 Excel 工作表上具有单元格中特定值的列,但它不起作用
我尝试了以下 VBA 脚本
Sub Hide_Forecasts()
Dim c As Range
For Each c In Range("E12:CF12").Cells
If c.Value = "Forecast" Then
c.EntireColumn.Hidden = True
End If
Next c
End Sub
Sub Unhide_Forecasts()
Dim c As Range
For Each c In Range("E12:CF12").Cells
If c.Value = "Forecast" Then
c.EntireColumn.Hidden = False
End If
Next c
End Sub
Sub CheckBox_For()
If CheckBox1.Value = True Then
Call Hide_Forecasts
Else
Call Unhide_Forecasts
End If
End Sub
请帮帮我
【问题讨论】:
-
没有工作是什么意思?您是否收到错误,如果是,那是哪一行以及错误消息是什么?
-
Call与Application.Run()可能需要研究...您需要指定这些是否都在同一个模块中,等等,就像 Warcupine 所说,详细说明您的问题。