Using VBA to manage conditional formatting rules

AnaJadeYu

New Member
Joined
Aug 20, 2019
Messages
2
Hi All,

I have a spreadsheet with a long list of informaton which has been formatted using conditional formatting. My problem is that a new CF rule is split up every time I add a row. I have written the following macro to re-set the conditional formating, so that my spreadsheet works in the correct way, but when I go to see all of the CF rules for the sheets, they are still there. How do I manage the acual CF rules using VBA?

Code:
Public Function LastRow() As Long
Application.Volatile
ActiveSheet.AutoFilterMode = False
LastRow = ActiveSheet.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
End Function





Private Sub Worksheet_Change(ByVal Target As Range)


If Sheet1.Range("D1").Value <> Sheet1.Range("E1").Value Then
MsgBox "Congratulations"
        
Sheet1.Range("E1").Value = Sheet1.Range("D1").Value
Range("A2:B12").FormatConditions.Delete
Range("A1:B1").Copy
Range("A2:B12").PasteSpecial

End If


End Sub


I appreciate any help you can give me.
 
Last edited by a moderator:

Excel Facts

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

Forum statistics

Threads
1,214,585
Messages
6,120,391
Members
448,957
Latest member
Hat4Life

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