Link to home
Start Free TrialLog in
Avatar of ExpExchHelp
ExpExchHelpFlag for United States of America

asked on

Hide/un-hide columns via VBA

A command button on my spreadsheet should hide/un-hide specified columns (in VBA code).    Please see attached XLS with VBA code (currently not working) and specific details as to what I would like to accomplish.

I'd welcome your feedback.   Thank you!

EEH
Hide-Unhide-Columns.xlsm
ASKER CERTIFIED SOLUTION
Avatar of Fabrice Lambert
Fabrice Lambert
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Consider using Custom Views

Create, apply, or delete a custom view

The this code will hide or unhide the columns. I have created two custom views one called FullView and the other called HiddenView.

Please note that  If you only have one Table in your entire Workbook, you cannot use Custom Views. The command is inactive.

Private Sub CommandButton1_Click()
    With ThisWorkbook
        If CommandButton1.Caption = "Hide Information" Then
            .CustomViews("HiddenView").Show
            CommandButton1.Caption = "Show Information"
        Else
            .CustomViews("FullView").Show
            CommandButton1.Caption = "Hide Information"
        End If
    End With
End Sub

Open in new window


Please note that Custom Views cannot be used if the workbook contains Tables
Hide-Unhide-Columns.xlsm
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ExpExchHelp

ASKER

Thank you... both solutions work great.   Appreciate your assistance.
Pleased to help