循环遍历范围并隐藏列VBA
我今天病得很重,而且对 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 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:
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 this
和
需要设置的对象变量来创建实例,并且“FALSE”<> “false”,使用 Ucase 忽略差异。
[]的
use this
and
Objects variables need set to create a instance, and "FALSE" <> "false", use Ucase to ignore diferences.
[]´s