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.
 

Some videos you may like

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
52,156
Office Version
365
Platform
Windows
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.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
52,156
Office Version
365
Platform
Windows
You are welcome.
Glad I was able to help!
:)
 

Watch MrExcel Video

Forum statistics

Threads
1,089,937
Messages
5,411,371
Members
403,362
Latest member
DoubleJay

This Week's Hot Topics

Top