ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   UDF - detect cell border (https://www.excelbanter.com/excel-programming/291207-udf-detect-cell-border.html)

Jason Morin[_2_]

UDF - detect cell border
 
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

Chip Pearson

UDF - detect cell border
 
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


"Jason Morin" wrote in message
...
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




Tom Ogilvy

UDF - detect cell border
 


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

--
Regards,
Tom Ogilvy


"Jason Morin" wrote in message
...
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





All times are GMT +1. The time now is 01:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com