VBA – Color Only Half of the Border of an Excel Cell

Coloring the border of an Excel cell is a trivial task. The LineColor feature in Excel is easy to use out of the box:

However, whenever half of the cell needs to be colored, the trick is a bit more tough and it includes VBA. The idea is to use the AddConnector method of Excel-VBA, which connects two dots with a connector. The position of these two dots could be set in relation to the cell, which we would like to border in half:

The whole code runs rather flawlessly, coloring half of the border of the cell, whichever is mentioned in Set myRange. If you want to make the code work for the currently selected cell, make sure to replace With Worksheets("Sheet1")  with With ActiveSheet and Set myRange = .Range("E10") with Selection.  In cases like these, you are allowed to use Select, it is not that bad.

This is how the code runs:

The VBA code is available also here!

Enjoy it 🙂 !

Tagged with: , , , , ,