VBA function to test borders

marcinpec

New Member
Joined
Jun 15, 2011
Messages
4
Hi,

I have a spreadseet where in column A I have values I need to test.
It looks like this:


-- removed inline image ---


What I need is a test in column B - to identify sites - in this case: Paris, Dublin, Berlin. I'm trying to write a function to be called out in column B - to identify cells which has up/down borders - to find "site names".

What I have so far is not working - any help please?

Public Function CheckIfBorders(cellTargetCell As Variant) As String

CheckIfBorders = "Site Name - NO"

If Range(cellTargetCell).Borders(xlEdgeBottom).LineStyle <> xlNone Then
If Range(cellTargetCell).Borders(xlEdgeTop).LineStyle <> xlNone Then
CheckIfBorders = "Site Name OK"
End If
End If
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Set it to range, then underneath you don't need to put

Code:
Range(cellTargetCell).Border

Just use:

Code:
 cellTargetCell.Border
 
Upvote 0
Hm,.... not working.

Maybe the way I call out the function has something to do with it?

Say:
- A3 value is "Berlin" and this cell has upper and bottom border
- A4 value is "9321-0" and has no bottom border.

In cell B3 I call out the function =CheckIfBorders(A3) and get error
Same for B4: =CheckIfBorders(A4) - I get an error.
 
Upvote 0
Try this in a module:

Code:
Function CheckBorder(Target As Range) As Boolean ' Could use String

If Target.Borders(xlEdgeTop).LineStyle <> xlNone And Target.Borders(xlEdgeBottom).LineStyle <> xlBottom Then
    CheckBorder = True ' Change this to something wrapped in "" if preferred
Else: CheckBorder = False ' Change this to something wrapped in "" if preferred
End If

End Function
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,254
Members
452,900
Latest member
LisaGo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top