Author: Oscar Cronquist Article last updated on January 09, 2018

Click to show or hide a column vba

Click a single cell in column D to hide or show the comments in column E. Selecting multiple cells won´t change anything.

VBA Code

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("D:D")) Is Nothing And Target.Cells.CountLarge = 1 Then
    If Range("E:E").EntireColumn.Hidden = True Then
        Range("E:E").EntireColumn.Hidden = False
        Range("E:E").EntireColumn.Hidden = True
    End If
End If
End Sub

Where to put the code?

  1. Right click on sheet name
  2. Click "View Code"
    Click to hide or show a column
  3. Paste code to sheet module
  4. Exit VB Editor and return to excel

Download excel *.xlsm file

Click to hide or show a column.xlsm