1
votes

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.

1

1 Answers

2
votes

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.

[]´s