Remove Gridlines

How to Enable & Disable gridlines in VBA ?

Follow below steps to remove gridlines :-

You can set DisplayGridlines property to true of Window Object to hide gridlines from active sheet.

							
  Sub S001_RemoveGridlines()
	ActiveWindow.DisplayGridlines = False
  End Sub
							

And, if you want to turn on the gridlines, set DisplayGridlines to true of Window Object.

							
  Sub S002_ShowGridlines()
    ActiveWindow.DisplayGridlines = True
  End Sub
							

You can also remove gridlines from the specified sheet: ActiveWindow.SheetViews(SheetIndex or SheetName).DisplayGridlines = False e.g.

							
  Sub S003_RemoveGridlinesFromSpecificSheet()
    ActiveWindow.SheetViews(3).DisplayGridlines = False
  End Sub
							

What to do if you want to remove gridlines from all the sheets, Well, it is also possible. I am going to tell you three ways to do it.

1.

							
  Sub S003_RemoveGridlinesFromAllSheets()
	Dim sh As Worksheet
  
	For Each sh In ThisWorkbook.Worksheets
	  sh.Activate
	  ActiveWindow.DisplayGridlines = False
	Next sh
  End Sub
							

2.

							
  Sub S004_RemoveGridlinesFromAllSheetsUsingGroups()
   Dim TotalSheetCount As Integer
   Dim sheetIndex As Integer
  
	TotalSheetCount = ThisWorkbook.Worksheets.Count
	
	For sheetIndex = 1 To TotalSheetCount
	   Worksheets(sheetIndex).Select Replace:=False
	Next sheetIndex
	ActiveWindow.DisplayGridlines = False
	Worksheets(1).Activate
  End Sub
							

3.

							
  Sub S004_RemoveGridlinesFromAllSheetsUsingSheetView()
   Dim TotalSheetCount As Integer
   Dim sheetIndex As Integer
  
	TotalSheetCount = ThisWorkbook.Worksheets.Count
	
	For sheetIndex = 1 To TotalSheetCount
	  ActiveWindow.SheetViews(sheetIndex).DisplayGridlines = False
	Next sheetIndex
  End Sub
							

If you want to turn on gridlines in each sheet, you can use the below code :

							
  Sub S006_ShowGridlinesForAllSheets()
   Dim sh As Worksheet
  
	For Each sh In ThisWorkbook.Worksheets
	  sh.Activate
	  ActiveWindow.DisplayGridlines = True
	Next sh
 End Sub
							

Stay connect with us.