I am trying to count the number of cells in a range that have a red border.
Tried different ways but something just isn't right. I can't get it to work.
Here is what I have.
Thanks for the help
PuJo
Tried different ways but something just isn't right. I can't get it to work.
Here is what I have.
Thanks for the help
PuJo
VBA Code:
Option Explicit
Public Function CountRedBorderedCells(MyRange As Range) As Integer
'=CountRedBorderedCells(B11:H16) (formula I use in the cell)
Dim MyBorderCount As Integer
Dim c As Variant
For Each c In MyRange
If c.Borders(xlEdgeLeft).Borders.ColorIndex = 3 And _
c.Borders(xlEdgeRight).Borders.ColorIndex = 3 And _
c.Borders(xlEdgeTop).Borders.ColorIndex = 3 And _
c.Borders(xlEdgeBottom).Borders.ColorIndex = 3 Then
MyBorderCount = MyBorderCount + 1
End If
Next c
CountRedBorderedCells = MyBorderCount
End Function