循环遍历范围和隐藏列 VBA
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7823748/
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
Looping through Range and Hiding Columns VBA
提问by SWilliams
I am super ill today and very new at VBA - not a recipe for success. I'm trying to loop through each cell in a (horizontal) range, and if the text inside the cell is FALSE then i want to hide that column. This is what I've got so far:
我今天病得很重,而且对 VBA 非常陌生——这不是成功的秘诀。我正在尝试遍历(水平)范围内的每个单元格,如果单元格内的文本为 FALSE,那么我想隐藏该列。这是我到目前为止所得到的:
Dim rRange As Range
Dim rCell As Range
rRange = Worksheets("Data").Range("W7:AH7").Cells
For Each rCell In rRange
If rCell.Value = "FALSE" Then rCell.Columns.EntireColumn.Hidden = True
Next rCell
End Sub
I get error "object variable or with block variable not set". Please could somebody point out where i'm going wrong? Thanks.
我收到错误“对象变量或块变量未设置”。请有人指出我哪里出错了吗?谢谢。
回答by Bruno Leite
use this
用这个
set rRange = Worksheets("Data").Range("W7:AH7").Cells
and
和
If Ucase(rCell.Value) = "FALSE" Then rCell.Columns.EntireColumn.Hidden = True
Objects variables need set to create a instance, and "FALSE" <> "false", use Ucase to ignore diferences.
对象变量需要设置来创建实例,并且“FALSE”<>“false”,使用Ucase忽略差异。
[]′s
[]的