Hide Columns

M

MrRJ

Hi,
I referred back to another entry about hiding columns and tried to use it.
It didn't work. I created a drop down list in A5. Then all across from E1
to HE1, I used a simple if statement if the headers in row 6 equal to what
the selected drop down is, then is give value of 1, else blank. Question is,
why doesn't this work? Please help.

Dim c As Range
Dim varvalue As Variant
For Each c In Application.Intersect(ActiveSheet.UsedRange,
ActiveSheet.Range("E1:HI1")).Cells
varvalue = c.Value
If IsNumeric(varvalue) Then
If varvalue <> 1 Then
c.EntireColumn.Hidden = True
End If
End If
Next c
 
D

Don Guillett

why not a simpler approach
Sub hidecolsif()
For Each c In Range("e1:hl1")
If c = 1 Then Columns(c.Column).Hidden = True
Next c
End Sub
 
M

MrRJ

Hey Don,

Boy, you are so smart! It is most definitely simpler. I added this line
first, to unhide all the cells first prior to the "selection".
Range("A:HB").EntireColumn.Hidden = False

It works beautifully. Thanks a million.

MrRJ
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top