vba 如何在VBA中隐藏多组列?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40686523/
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
How to hide multiple sets of columns in VBA?
提问by ranopano
I would like to hide certain columns when a macro is run. How do I do this?
我想在运行宏时隐藏某些列。我该怎么做呢?
I know how to do it by a range of columns ("B:D")
using:
我知道如何通过一系列列("B:D")
使用:
Columns("B:D").EntireColumn.Hidden = True
But I'm not sure how to specify multiple columns that are not next to each other.
但我不确定如何指定多个不相邻的列。
I would need to hide columns: B, C, F, G, I, J, K, L, N.
我需要隐藏列:B、C、F、G、I、J、K、L、N。
回答by YowE3K
Range("B:C,F:G,I:L,N:N").EntireColumn.Hidden = True
(Edited to fixed the bug noticed by Slai - have to have "N:N" and not just "N".)
(编辑以修复 Slai 注意到的错误 - 必须有“N:N”而不仅仅是“N”。)