VBA Borders Around Cells and Ranges

In Excel, you can use VBA to draw borders around cells, ranges, and selected ranges.

First, open the VBA Editor (Alt + F11) to insert the code.

Borders around cells and ranges

Let’s draw some borders around a single cell. In the example, we are going to specify exactly which cell we want to use.

This is the simplest code to draw a border around all edges at once.

You can also do it for a range.

Borders around cells and ranges

You can use the following code in order to make borders around the currently selected cell(s).

But if you try to do it around more than a single cell, you are going to get the following result.

Additional parameters

We can modify this code a bit in order to give it additional options, such as line color and thickness.

The following code will result in the following borders.

If you want to use color from the drawing application, where the value is written as a hexadecimal number. First, you have to convert this value into decimals.

You can do it using the following code.

And this is the result.

Tomasz Decker is an Excel specialist, skilled in data analysis and financial modeling.