UDF - detect cell border

  • Thread starter Thread starter Jason Morin
  • Start date Start date
J

Jason Morin

I'm struggling with a simple UDF (it might require 2). I'd
like to return TRUE/FALSE if a cell has a top *or* bottom
border. Something like:

Function IsBorder(cell As Range) As Boolean
IsBorder = cell.Borders(xlEdgeTop)
End Function

Thanks!
Jason
 
Jason,

Try something like

Function HasBorder(Rng As Range) As Boolean
If Rng.Borders(xlEdgeTop).LineStyle <> xlNone Or _
Rng.Borders(xlEdgeBottom).LineStyle <> xlNone Then
HasBorder = True
Else
HasBorder = False
End If
End Function


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Function Isborder(cell As Range) as Boolean
Dim bTop As Boolean, bBottom As Boolean
Application.Volatile
bTop = True
bBottom = True
With cell.Borders(xlEdgeTop)
If .Weight = 2 And .LineStyle = -4142 _
And .ColorIndex = -4142 Then
bTop = False
End If
End With
With cell.Borders(xlEdgeBottom)
If .Weight = 2 And .LineStyle = -4142 _
And .ColorIndex = -4142 Then
bBottom = False
End If
End With
Isborder = bTop Or bBottom
End Function
 
Back
Top