In this article, we will demonstrate 3 quick ways to remove Gridlines in Excel using VBA. To demonstrate our methods, we will use the following dataset with 3 columns: “Name“, “Gender”, and “City“.
If the Developer tab is not visible on the Ribbon, enable it as follows:
- Go to File → Options → Customize Ribbon tab → select Developer.
- Click OK.
Method 1 – Removing Gridlines from Active Worksheet
Bring up a VBA Module window, where we will enter our code.
- From the Developer tab → select Visual Basic. Alternatively, press ALT+F11.
The VBA window will pop up.
- From the Insert tab, select Module.
- Enter the following code in the VBA Module window:
Sub Remove_Gridlines_Active_Sheet()
ActiveWindow.DisplayGridlines = False
End Sub
VBA Code Breakdown
- We name our Sub procedure Remove_Gridlines_Active_Sheet.
- We set the DisplayGridlines property to False.
Our code will execute and remove Gridlines from the active sheet.
Method 2 – Remove Gridlines from Specific Worksheet
In this section, we will hide Gridlines from a specific sheet named “sSheet”.
Steps:
- As shown in the first method, bring up a Module window.
- Enter the following code in this window:
Sub Hide_Gridlines_Specific_Sheet()
Dim xSheet As Worksheet
Set xSheet = Worksheets("sSheet")
'Gridlines in "sSheet" will be hidden
xSheet.Activate
ActiveWindow.DisplayGridlines = False
End Sub
VBA Code Breakdown
- We name our Sub procedure Hide_Gridlines_Specific_Sheet.
- We declare the variable types.
- We define the specific Sheet.
- We activate that Sheet and set the DisplayGridlines property to False.
- As shown in method 1, Save and Run this Module.
The code will remove the Gridlines in the selected sheet.
Method 3 – Remove Gridlines From Workbook
Now we will re-enable the Gridlines in all sheets, and then using a VBA code we will remove the Gridlines from the entire workbook using a For Each Next Loop.
Steps:
- From the View tab → select Gridlines for all the Sheets.
This will re-enable Gridlines in the workbook.
- As shown in the first method, bring up a Module window.
- Enter the following code in that window:
Sub Hide_Gridlines_Workbook()
Dim xSheet As Worksheet
'Gridlines in Workbook will be hidden
For Each xSheet In Worksheets
xSheet.Activate
ActiveWindow.DisplayGridlines = False
Next xSheet
End Sub
VBA Code Breakdown
- We name our Sub procedure Hide_Gridlines_Workbook.
- We declare the variable type.
- We use a For Each Next loop to go through all the sheets of the workbook.
- We activate all sheets inside the workbook and set the DisplayGridlines property to False.
- As shown in method 1, Save and Run this Module.
The code will remove Gridlines in the whole workbook using VBA.
Download Practice Workbook
Related Articles
- How to Remove Gridlines in Excel for Specific Cells
- How to Remove Vertical Line in Excel
- How to Remove Gridlines in Excel When Printing
<< Go Back to Remove Gridlines | Gridlines | Learn Excel
Get FREE Advanced Excel Exercises with Solutions!