Return to VBA Code Examples

VBA Cell Borders

This tutorial will show how to adjust cell border settings in VBA.

Formatting Borders

Top Border – Double Line

First let’s look at an example of how to set a blue, thick, doubled top border to the cell B3 on Sheet1:example border

Notice we use a With Statement to simplify our coding.

We access the the top border with .Borders(xlEdgeTop).

Other Cell Borders

Instead you can access other borders, including diagonals:

border example2

Inside Borders

You can also adjust horizontal (xlInsideHorizontal) and vertical (xlInsideVertical) borders for all cells in a range:

inside horizontal borders


The LineStyle property can be changed to xlContinuous, xlDot, xlDash, xlDashDot, xlDashDotDot, xlDouble, xlSlantDashDot and xlLineStyleNone.

The Weight property can be either xlHariline, xlThin, xlMedium and xlThick. You will have this result with the code below:

border weight

Border colors can be set as ColorIndex or Color (RGB, serial number or vbColor). See more information about color settings here.

You can add borders around a range with a one-line command as well:


VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! vba save as

Learn More!