How to Remove Gridlines in Excel Using VBA

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“.

How to Remove Gridlines in Excel Using VBA 1

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.

How to Remove Gridlines in Excel Using VBA 2


Method 1 – Removing Gridlines from Active Worksheet

Steps:

Bring up a VBA Module window, where we will enter our code.

  • From the Developer tab → select Visual Basic. Alternatively, press ALT+F11.

How to Remove Gridlines in Excel Using VBA 3

The VBA window will pop up.

  • From the Insert tab, select Module.

How to Remove Gridlines in Excel Using VBA 4

  • Enter the following code in the VBA Module window:
Sub Remove_Gridlines_Active_Sheet()
    
    ActiveWindow.DisplayGridlines = False
    
End Sub

How to Remove Gridlines in Excel Using VBA 5

VBA Code Breakdown

  • We name our Sub procedure Remove_Gridlines_Active_Sheet.
  • We set the DisplayGridlines property to False.
  • Save the Module.
  • Put the cursor inside the Sub procedure and press the Run button.

How to Remove Gridlines in Excel Using VBA 6

Our code will execute and remove Gridlines from the active sheet.

How to Remove Gridlines in Excel Using VBA 7


Method 2 – Remove Gridlines from Specific Worksheet

In this section, we will hide Gridlines from a specific sheet named “sSheet”.

Steps:

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 2

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.

The code will remove the Gridlines in the selected sheet.

VBA Code 2 Output


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.

Turn On Gridlines

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

How to Remove Gridlines in Excel Using VBA

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.

The code will remove Gridlines in the whole workbook using VBA.

Workbook Code


Download Practice Workbook


Related Articles


<< Go Back to Remove Gridlines | Gridlines | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Rafiul Haq
Rafiul Haq

Rafiul Haq worked as an Excel and VBA Content Developer in Exceldemy for over two years and published almost 200 articles for the website. He is passionate about exploring new aspects of Excel and VBA. He received his Bachelor of Science in Mechanical and Production Engineering (MPE) from the Islamic University of Technology. Rafiul furthered his education by obtaining an MBA in Finance from the Institute of Business Administration (IBA) at the University of Dhaka. Apart from creating... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo