macro to hide # of columns based on value

  • Thread starter Thread starter Graeme
  • Start date Start date
G

Graeme

I am trying to write a macro which will hide certain columns based upon the
value of a cell. For example, if cell value = 1, hide columns A:Q, if value
= 2, hide columns B:Q, if value = 3, hide C:Q and so on. Is there a quick
way of doing this. Thank you.
 
not much info to work with, i used cell T1 on sheet1 as the value for the
first column

Sub test()
Dim colnum As Long
Dim ws As Worksheet
Set ws = Worksheets("sheet1")
colnum = ws.Range("t1").Value
With ws
.Columns(colnum).Resize(, 18 - colnum).EntireColumn.Hidden = True
End With
End Sub
 
Thank you.

Gary Keramidas said:
not much info to work with, i used cell T1 on sheet1 as the value for the
first column

Sub test()
Dim colnum As Long
Dim ws As Worksheet
Set ws = Worksheets("sheet1")
colnum = ws.Range("t1").Value
With ws
.Columns(colnum).Resize(, 18 - colnum).EntireColumn.Hidden = True
End With
End Sub
 
Back
Top