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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 11:34:08  来源:igfitidea点击:

How to hide multiple sets of columns in VBA?

excelvbaexcel-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”。)