How to Hide Gridlines in Excel VBA

Written by shawn mcclain
  • Share
  • Tweet
  • Share
  • Email

The Excel gridlines run between the columns and row of the spreadsheet, allowing you to see where each individual cell is located. While there is a setting in the "View" ribbon that lets you switch the gridlines off, you can also use Excel's built-in programming language, Visual Basic for Applications (VBA), to turn them off. Using VBA code to complete the process allows you to switch off the gridlines automatically as the program processes your code.

Skill level:
Moderately Easy


  1. 1

    Open the Excel file that holds your spreadsheet and VBA information. Once the file opens up, press "Alt" and "F11" to launch the VBA console.

  2. 2

    Select the module that holds your VBA code from the list of sheets and modules on the left side of the VBA console.

  3. 3

    Place your cursor into your VBA code on the right half of the console, where you want to enter the code to remove your gridlines. Type the following code into the Excel console: "ActiveWindow.DisplayGridlines = False". Click the "X" in the upper-right corner of the VBA console to close it. When you choose to run the macro from the "Developer" tab, the gridlines will disappear.

Tips and warnings

  • If you want to turn the gridlines off while the code is running, but return them to their original state once the macro ends, you can add two lines to your code to get it done. Just add "gridlineState = ActiveWindow.DisplayGridlines" to your code's variables and "ActiveWindow.DisplayGridlines = gridlineState" to the end of your 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.