Hide columns using a button

If you need to hide certain columns using a button, you can use this code.  It will even change the command button text to Hide Columns and then again change it to Unhide Columns.

 

Sub Hide_C()

Dim C_ell As Range

ActiveSheet.Shapes.Range(Array("Button 2")).Select

If Selection.Characters.Text = "Unhide Columns" Then

Columns.Hidden = False

Selection.Characters.Text = "Hide Columns"

Else

For Each C_ell In Range("B1", Cells(1, Columns.Count).End(xlToLeft))

If C_ell = "x" Then C_ell.Columns.Hidden = True

Next

Selection.Characters.Text = "Unhide Columns"

End If

Range("A2").Select

End Sub

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Terms and Conditions of use

The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.