To remove all borders in Excel using VBA, you can apply the BorderAround method with LineStyle = xlNone or set Border(xlEdgeLeft) through xlEdgeRight to xlNone. The most reliable and concise approach is using Selection.Borders.LineStyle = xlNone or Range("A1:Z100").Borders.LineStyle = xlNone. No external tools or add-ins are required—just Excel with VBA enabled and basic familiarity with the VBA editor.
What You'll Need
- Microsoft Excel (2010 or later, including Microsoft 365)
- A workbook with cells that have borders you want to remove
- Excel VBA enabled (File > Options > Trust Center > Trust Center Settings > Macro Settings > Enable macros)
- Basic understanding of selecting ranges in Excel
Step-by-Step
- Open your Excel workbook.
- Press Alt + F11 to open the Visual Basic for Applications (VBA) editor.
- In the VBA editor, go to Insert > Module to create a new blank module. If the Project Explorer is not visible, press Ctrl + R to display it.
- Copy and paste one of the following code snippets into the module, depending on your scope:
- To remove borders from the currently selected cells:
Sub RemoveBordersFromSelection() Selection.Borders.LineStyle = xlNone End Sub - To remove borders from a specific range (e.g., A1:D50 on the active sheet):
Sub RemoveBordersFromRange() ActiveSheet.Range("A1:D50").Borders.LineStyle = xlNone End Sub - To remove borders from the entire used range on the active sheet:
Sub RemoveBordersFromUsedRange() ActiveSheet.UsedRange.Borders.LineStyle = xlNone End Sub
- To remove borders from the currently selected cells:
- Close the VBA editor by clicking the X or pressing Alt + Q.
- Return to Excel. Press Alt + F8 to open the Macro dialog box.
- Select the macro you created (e.g.,
RemoveBordersFromSelection), then click Run. - Verify the borders are gone by checking the affected cells—no gridlines or outline borders should remain.
Common Mistakes
- Using the wrong object reference: Forgetting to specify
ActiveSheetor a specific worksheet can cause the macro to act on the wrong sheet if multiple sheets are open. Always qualify ranges (e.g.,Sheets("Sheet1").Range(...)). - Confusing cell borders with gridlines: Gridlines are screen-only and unaffected by
Borders.LineStyle = xlNone. To hide gridlines, useActiveWindow.DisplayGridlines = False—this is separate from removing borders. - Running the macro on the wrong selection: If using
Selection.Borders.LineStyle = xlNone, ensure the correct range is selected before running the macro. Accidentally selecting an entire column or sheet can cause performance lag or unintended changes. - Not enabling macros: If macros are disabled in Trust Center settings, the macro will not run and no error may appear—just check macro security under File > Options > Trust Center.
- Assuming the code removes all formatting: This code only removes borders. Fill color, font styles, and other formatting remain unchanged.
Tips
- Test on a copy first: Run the macro on a duplicate of your workbook to avoid accidental data loss.
- Use
xlHairlinefor thin borders, notxlNone: If you want minimal borders instead of none, useBorders.LineStyle = xlHairlineas an alternative—though notexlHairlineis only supported in newer Excel versions. - Apply to multiple sheets: To remove borders across all sheets, loop through
ThisWorkbook.Worksheetsin your macro:Sub RemoveBordersOnAllSheets() Dim ws As Worksheet For Each ws In ThisWorkbook.Worksheets ws.UsedRange.Borders.LineStyle = xlNone Next ws End Sub - Undo is available: If you run the macro by mistake, press Ctrl + Z immediately—Excel tracks border changes as undoable actions.
- Combine with other cleanup tasks: Add lines like
Selection.Interior.ColorIndex = xlNoneto also remove background fill in one pass.
Troubleshooting
If your macro does not remove borders, follow these steps in order:
- Restart Excel: Close and reopen the workbook. Sometimes Excel caches old macro states or has temporary UI glitches.
- Verify macro security: Go to File > Options > Trust Center > Trust Center Settings > Macro Settings. Ensure Enable all macros (or at least Disable all macros with notification) is selected. If macros are disabled, the code will not execute.
- Check for merged cells: Merged cells can retain partial border visibility. Unmerge first (
Selection.UnMerge), then apply the border removal code. - Confirm correct range: If using
ActiveSheet.Range(...), ensure the sheet name matches exactly (case-insensitive, but spelling must be identical). Try usingActiveCell.Worksheetto avoid ambiguity. - Test with a simple range: Manually select a small range with visible borders (e.g., A1:B2), then run a minimal macro:
Sub TestRemove() Selection.Borders.LineStyle = xlNone End SubIf this works, your original range reference may be incorrect. - Check for protected sheets: If the worksheet is protected, the macro may fail silently. Unprotect it first (Review > Unprotect Sheet), or include
ActiveSheet.Unprotect Password:="yourpassword"(replaceyourpasswordwith the actual password) before the border removal line. - Look for conditional formatting: Conditional formatting can override manual borders. Go to Home > Conditional Formatting > Clear Rules to remove formatting-based borders before running the VBA code.
Frequently Asked Questions
Does removing borders with VBA affect print output?
Yes—borders removed via Borders.LineStyle = xlNone will not appear in printouts either. If you only want to hide borders on screen but keep them for printing, you must adjust the Borders.Weight or Color instead of setting LineStyle to xlNone.
Can I undo the border removal after closing and reopening the workbook?
No. Undo history is cleared when the workbook is closed. To recover borders, you must reapply them manually or use a backup. Always save a version before running border-removal macros.
Will this remove borders from tables (ListObjects)?
Yes, but only if the table is part of the range you target. However, table formatting (like banded rows) may re-add borders automatically. To prevent this, modify the table style: go to Table Design > Table Styles, click the down arrow, and choose Clear to reset formatting.
Why do some borders reappear after I run the macro?
This usually happens if the cells are part of a table (ListObject), have conditional formatting rules that apply borders, or the worksheet is protected. Check for these elements and adjust your macro to unprotect sheets or clear conditional formatting first.
Is there a way to remove borders only from specific sides (e.g., top and bottom)?
Yes. Use targeted border constants. For example, to remove only top and bottom borders from a selection:
With Selection.Borders
.Item(xlEdgeTop).LineStyle = xlNone
.Item(xlEdgeBottom).LineStyle = xlNone
End With Other constants include xlEdgeLeft, xlEdgeRight, xlInsideVertical, and xlInsideHorizontal.
Does this work in Excel Online or mobile?
No. VBA macros are not supported in Excel for the web, iOS, or Android. You must use the desktop version of Excel (Windows or macOS) to run this code.