vba 通过单个按钮隐藏和取消隐藏行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23656870/
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
Hide and Unhide Rows via Single Button
提问by HolyCow7
I have looked through a couple of the questions that have previously been posted relating to this topic and believe someone on this community will be able to assist with my inquiry. I am fairly novice to VBA so I apologize in advance if my question is elementary.
我已经浏览了之前发布的与此主题相关的几个问题,并相信该社区中的某个人将能够帮助我进行查询。我对 VBA 相当新手,所以如果我的问题很初级,我提前道歉。
My goal is to use a single macro tied to a button to Hide and then Un-hide a selected number of rows (these rows will always be the same) after clicking the button again. I want each of these actions to be completed by separate, solitary clicks without utilizing any Message Boxes or timed delays. I've recorded a macro with the actions & their criteria and pasted it below. The only missing piece is the code needed to separate these actions before being clicking the button again and running the next action. Thanks in advance for the assistance.
我的目标是使用绑定到按钮的单个宏来隐藏,然后在再次单击按钮后取消隐藏选定数量的行(这些行将始终相同)。我希望这些操作中的每一个都通过单独的、单独的点击完成,而不使用任何消息框或定时延迟。我已经记录了一个带有动作及其标准的宏并将其粘贴在下面。唯一缺少的部分是在再次单击按钮并运行下一个操作之前将这些操作分开所需的代码。预先感谢您的帮助。
Sub Macro1()
Rows("7:21").Select
Selection.EntireRow.Hidden = True
Rows("7:21").Select
Selection.EntireRow.Hidden = False
End Sub
回答by Rory
You can toggle it with this:
你可以用这个来切换它:
Sub ToggleRows()
With Rows("7:21")
.Hidden = Not .Hidden
End With
End Sub
回答by Jacob Lambert
Try something similar to this:
尝试类似的事情:
Sub Macro1()
' Macro1 Macro ' '
Rows("7:21").Select
If Rows("7:21").Hidden = True Then
Selection.EntireRow.Hidden = False
Else
Selection.EntireRow.Hidden = True
End If
End Sub
All that is left to do is attach it to a button.
剩下要做的就是将其附加到按钮上。