How to Hide Gridlines in Excel VBA
By Shawn McClain
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.
Step 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.
Step 2
Select the module that holds your VBA code from the list of sheets and modules on the left side of the VBA console.
Step 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.
References
Tips
- 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.
Writer Bio
Shawn McClain has spent over 15 years as a journalist covering technology, business, culture and the arts. He has published numerous articles in both national and local publications, and online at various websites. He is currently pursuing his master's degree in journalism at Clarion University.