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

1

1 Answer 1

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

4
  • 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
    Commented Oct 25, 2015 at 22:32
  • I updated the answer
    – paul bica
    Commented Oct 25, 2015 at 23:51
  • 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
    Commented Oct 27, 2015 at 0:18
  • I updated it so it will work on the currently selected range of cells (for the ActiveSheet)
    – paul bica
    Commented Oct 27, 2015 at 2:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .