vba Excel:如何使用复选框形式 marco 隐藏 MAC 上的列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21590250/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Excel: How to use a checkbox form marco to hide column on MAC
提问by Snoobie
I'm using an activeX checkbox with the following Macro in my worksheet:
我在工作表中使用带有以下宏的 activeX 复选框:
Private Sub CheckBox1_Click()
If CheckBox1 = True Then
Columns("P:V").Hidden = True
Else
Columns("P:V").Hidden = False
End If
End Sub
And it works fine on my PC. But when I try to do it on Mac, it doesn't work since Mac doesn't have activeX support. I tried using a regular form control checkbox, but it doesn't appear to function at all when I use this macro. Anyone have any ideas? I'm kind of a VBA/Excel noob.
它在我的电脑上运行良好。但是当我尝试在 Mac 上执行此操作时,它不起作用,因为 Mac 不支持 activeX。我尝试使用常规表单控件复选框,但当我使用此宏时,它似乎根本不起作用。谁有想法?我是一个 VBA/Excel 菜鸟。
采纳答案by Tim Williams
If you put two Forms checkboxes on a sheet and name them "cbB" and "cbC" you can assign the macro below to both of them. Which column is affected will depend on which checkbox triggers the Sub.
如果您在工作表上放置两个表单复选框并将它们命名为“cbB”和“cbC”,您可以将下面的宏分配给它们。哪一列受到影响取决于哪个复选框触发 Sub。
Code is for a regular module: if you want it in the sheet module then I would replace ActiveSheet
with Me
代码用于常规模块:如果您希望在工作表模块中使用它,那么我将替换ActiveSheet
为Me
Sub CheckBox_Click()
Dim vis As Boolean, ac As String, col As String
ac = Application.Caller
With ActiveSheet
vis = (.Shapes(ac).ControlFormat.Value = 1)
Select Case ac
Case "cbB": col = "B"
Case "cbC": col = "C"
End Select
If col <> "" Then .Columns(col).Hidden = vis
End With
End Sub