Macro to Hide Columns

JDeMaro22
StarLounger
Posts: 94
Joined: 16 Oct 2021, 16:22

Macro to Hide Columns

Post by JDeMaro22 »

Hi Everyone!

I'm looking for a macro that will hide 6 columns at a time when I press a button. I want to always keep column A but hide B-G (columns 2-7) when I press a button. This report shows weekly data that users manually input data into for the year, I'd like users to be able to hide previous weeks to make inputting new data easier. Is this something you can help me with?

Thanks,

Josh
Capture.PNG
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78444
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Macro to Hide Columns

Post by HansV »

To hide columns B:G:

Code: Select all

Sub HideB2G()
    Range("B1:G1").EntireColumn.Hidden = True
End Sub
Or do you want to hide different columns each time the button is pressed?
Best wishes,
Hans

JDeMaro22
StarLounger
Posts: 94
Joined: 16 Oct 2021, 16:22

Re: Macro to Hide Columns

Post by JDeMaro22 »

The first time it would be B-G but the next would need to be H-M and so forth. Is this possible?

adeel1
3StarLounger
Posts: 264
Joined: 04 Oct 2017, 15:47

Re: Macro to Hide Columns

Post by adeel1 »

Code: Select all

Sub hide_col()
Dim v As Long

v = Range("b1:z1").SpecialCells(12).Column
Cells(1, v).Resize(, 6).EntireColumn.Hidden = True

End Sub

User avatar
HansV
Administrator
Posts: 78444
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Macro to Hide Columns

Post by HansV »

Thanks, adeel!
Best wishes,
Hans

adeel1
3StarLounger
Posts: 264
Joined: 04 Oct 2017, 15:47

Re: Macro to Hide Columns

Post by adeel1 »

Thx of you and this forum, who is providing great helps. :clapping:

Adeel

JDeMaro22
StarLounger
Posts: 94
Joined: 16 Oct 2021, 16:22

Re: Macro to Hide Columns

Post by JDeMaro22 »

perfect thank you so much everyone