Conditional Formatting with VBA: Border at Every Change in Value in a Given Column

lneidorf

Board Regular
Joined
May 20, 2004
Messages
84
Hi there.

I'm using Excel for Mac 16.53, with an Office 365 subscription.

I'd like to create a macro for repeated use to apply borders to my spreadsheets whenever there's a change in value in column B. But I want to do this via Conditional Formatting, as the values in the spreadsheets can change over time.

I've got some code that's erroring out. Here's my code:
VBA Code:
Sub FamilyBanding()
'Define Range
Dim MyRange As Range
Set MyRange = Selection
 
'Delete Existing Conditional Formatting from Range
MyRange.FormatConditions.Delete
 
'Apply Conditional Formatting
MyRange.FormatConditions.Add Type:=xlExpression, _
        Formula1:="=$B3<>$B2"
    With MyRange.FormatConditions(1).Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ThemeColor = 5
        .TintAndShade = 0
        .Weight = xlThin
    End With
End Sub

When I run this, I get a Runtime Error 1004: Unable to set the LineStyle property of the Border Class. It seems to be stuck on the ".LineStyle = xlContinuous" line. I should note that it does successfully create the formatting rule, with the proper formula and applied range.

I'd be most grateful for your help.

Thanks!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

lneidorf

Board Regular
Joined
May 20, 2004
Messages
84
Problem solved.

Apparently it doesn't like the "Borders(xlEdgeBottom)" property. When I change this to "Borders(xlBottom)", it runs.
 

Forum statistics

Threads
1,148,238
Messages
5,745,568
Members
423,960
Latest member
sainoz

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
Top