How to Hide Gridlines in Excel VBAby 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.
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.
Select the module that holds your VBA code from the list of sheets and modules on the left side of the VBA console.
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.
- check 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.