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

lneidorf

Board Regular
Joined
May 20, 2004
Messages
97
Office Version
  1. 365
Platform
  1. Windows
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

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Problem solved.

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

Forum statistics

Threads
1,214,905
Messages
6,122,178
Members
449,071
Latest member
cdnMech

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