How to Use VBA to Hide Columns

Written by ty arthur
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Use VBA to Hide Columns
A few lines of VBA code hides your Excel columns. (typing image by from

The Visual Basic for Applications (VBA) editor included in Microsoft Excel allows users to create custom code for manipulating spreadsheets. VBA lets you make a variety of changes to your Excel file, such as summing the contents of rows or hiding columns that don't need to be seen. Hiding any of the columns in a spreadsheet doesn't take a degree in computer programming, as you only need to type a few brief lines of code.

Skill level:
Moderately Easy

Other People Are Reading


  1. 1

    Open Microsoft Excel and click the sheet tab at the bottom of the screen containing the column to be hidden. Note down the letter assigned to the column, such as "D" or "F."

  2. 2

    Click the "Developer" tab at the top of the window. Click the "Visual Basic" icon in the "Code" section. Double-click the sheet name at the left end of the window that corresponds to the appropriate worksheet.

  3. 3

    Type the opening and closing "Sub" commands. For instance if you want to name the Sub "Column_Hiding," type "Sub Column_Hiding ()" and move down a line and type "End Sub."

  4. 4

    Navigate to the line in between the opening and closing "Sub" command. Use the "Range" property to identify which column needs to be hidden. For instance, type "Range("D:D").Select" if you want to hide the "D" column.

  5. 5

    Move down a line and type "Selection.EntireColumn.Hidden = True." Click the green arrow icon to run the code and hide the column.

Tips and warnings

  • The VBA code doesn't have to be run directly through the Visual Basic editing window. Close the window and return to the worksheet. Click the "Macro" button in the "Code" heading. Click the name you used earlier for the Sub, such as "Column_Hiding," and select "Run."
  • Making the column visible again only requires changing a single word in the code. Change "Selection.EntireColumn.Hidden = True" into "Selection.EntireColumn.Hidden = False" and run the code.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.