Change color existing irregular borders - Excel

1

I would like to change the existing border color of multiple cells -some of them have only a border at the top/ left or none at all etc- in Excel.

Is there a standard option for this, or is can this been done with a macro?

EDIT:

Apparently my description was not clear enough. I am trying to change the border color (of cells that already exist) of a calendar. So that are 12 tabs and lots of lines.

As you can see in the image below, not all cells have the same border (style) eg. borders surrounding the entire cell (some do, some cells have only a line at the side of top/ bottom and some have non at all). I am trying to change the color of them all without having to re-draw all of the lines. I would like to 'update' the current color.

example of borders

Ludo

Posted 2015-10-25T17:57:56.450

Reputation: 77

Changing the Color of a Cell Border is the first result returned from search for "excel 2013 change cell border color" – DavidPostill – 2015-10-25T18:30:41.863

Answers

3

You can use VBA code like this - it will affect current selection (if the selection is a Range of cells

Option Explicit

Public Sub setBorders()
    Dim cel As Range, clr1 As Long, clr2 As Long

    clr1 = vbWhite  'if cell border color is different than white, and has LineStyle

    clr2 = vbRed    'change its color to vbRed

    If TypeOf Selection Is Range Then
        For Each cel In Selection       'select your Range
            With cel
                With .Borders(xlEdgeLeft)
                    If .Color <> clr1 And .LineStyle <> xlNone Then .Color = clr2
                End With
                With .Borders(xlEdgeTop)
                    If .Color <> clr1 And .LineStyle <> xlNone Then .Color = clr2
                End With
                With .Borders(xlEdgeBottom)
                    If .Color <> clr1 And .LineStyle <> xlNone Then .Color = clr2
                End With
                With .Borders(xlEdgeRight)
                    If .Color <> clr1 And .LineStyle <> xlNone Then .Color = clr2
                End With
            End With
        Next
    End If
End Sub

border colors


To use it open the VBA editor - Alt + F11, and paste the code in a standard VBA module

paul bica

Posted 2015-10-25T17:57:56.450

Reputation: 1 190

Thanks for your reaction, however I am tying to do something more difficult. I am aware of how to google ;) I amended my original question with more information. – Ludo – 2015-10-25T22:32:08.950

I updated the answer – paul bica – 2015-10-25T23:51:58.320

Cool, thanks! That's working, but is there a way I can make it a 'global' macro. Calling this active sheet, instead of Sheet1 – Ludo – 2015-10-27T00:18:33.787

I updated it so it will work on the currently selected range of cells (for the ActiveSheet) – paul bica – 2015-10-27T02:29:31.000