ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   macro to hide # of columns based on value (https://www.excelbanter.com/excel-programming/402360-macro-hide-columns-based-value.html)

Graeme

macro to hide # of columns based on value
 
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.

Gary Keramidas[_2_]

macro to hide # of columns based on value
 
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

--


Gary Keramidas


"Graeme" wrote in message
...
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.



Graeme

macro to hide # of columns based on value
 
Thank you.

"Gary Keramidas" wrote:

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

--


Gary Keramidas


"Graeme" wrote in message
...
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.





All times are GMT +1. The time now is 05:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com