VBA Code to Unhide columns

chelberg3

New Member
Joined
Oct 24, 2019
Messages
2
I'd like to unhide columns based on clicking the a button that I have created. When the user clicks the button, columns F-I would unhide. When the button is clicked again it moves to unhide the next group of columns J-M and so on. I'd like to use the same button to keep this quoting worksheet clean for the salesman. What is the best way to do this? do i need multiple macros that get called and run if the columns are already shown?

Thanks for any help.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Welcome to the Board!

Try attaching this code to your macro button.
Code:
Sub UnhideColumns()

    Dim c As Long
    
'   Indicate what columns to include (F=6, ...)
    For c = 6 To 100 Step 4
'       Check to see if column is hidden
        If Columns(c).Hidden = True Then
'           Unhide columns
            Range(Columns(c), Columns(c + 3)).Hidden = False
            Exit Sub
        End If
    Next c
    
End Sub
Note: you should update the "100" in the "For ..." line to reflect the maximum possible hidden column you may have.
 
Upvote 0
You are welcome.
Glad I was able to help!
:)
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top