Excel Vba del conditional formating

yeat

New Member
Joined
Jan 25, 2022
Messages
18
Office Version
  1. 2019
Platform
  1. Windows
Hello, I can't delete the conditional formatting, please help, thanks. below is my code. My workbook got multi conditional formatting, cant del all in one time.

VBA Code:
Sub ReadingLayout()
'add sub code
    sCode = "Private Sub Worksheet_SelectionChange(ByVal Target As Range)" & vbCrLf & _
          "' *** Code Added By VBA ***" & vbCrLf & _
          "If Application.CutCopyMode = False Then  " & vbCrLf & _
          "Application.Calculate" & vbCrLf & _
          "End If" & vbCrLf & _
          "End Sub" & vbCrLf
    With ActiveWorkbook.VBProject.VBComponents(ActiveSheet.Name).CodeModule
        NextLine = .CountOfLines + 1
        .InsertLines NextLine, sCode
    End With
'add formatcondition
    Dim rng As Range
    Dim FC1 As FormatCondition, FC2 As FormatCondition
    
    Set rng = ActiveSheet.Range("A1:XFD9999")
    
    Set FC1 = rng.FormatConditions.Add(xlExpression, Formula1:="=OR(CELL(""col"")=COLUMN(),CELL(""row"")=ROW())")
    
    With FC1
        .SetFirstPriority
        .Interior.Color = RGB(252, 213, 181)
    End With

End Sub


VBA Code:
Sub DelReadingLayout()
'del sub code
    Dim CodeInd As Long, sNo, eNo, bFlag
    Const PROC_NAME = "PRIVATE SUB WORKSHEET_SELECTIONCHANGE(BYVAL TARGET AS RANGE)"
    bFlag = False
    With ActiveWorkbook.VBProject.VBComponents("sheet1").CodeModule
        For CodeInd = .CountOfDeclarationLines + 1 To .CountOfLines
            Select Case VBA.UCase$(Trim(.Lines(CodeInd, 1)))
            Case PROC_NAME
                bFlag = True
                sNo = CodeInd
            Case "END SUB"
                If bFlag Then
                    eNo = CodeInd
                    Exit For
                End If
            End Select
        Next CodeInd
        'For i = eNo To sNo Step -1
        '   .DeleteLines i
        'Next
        .DeleteLines sNo, eNo - sNo + 1
    End With

[B][U]'del format (broken)[/U][/B]
    Dim FC1 As FormatCondition
    
    For Each FC1 In ActiveSheet.Cells.FormatConditions
        If FC1.Interior.Color = RGB(252, 213, 181) Then
            FC1.Delete
        End If
    Next FC1
        
End Sub
1643099764712.png
1643099736660.png
1643099798232.png
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
it's probably not the cause but you never know, go to file -> info and check permissions.

info.PNG


maybe I can be more helpful if you send me the file.
 
Upvote 0
Probably having duplicate rules is what causing the problem.

dup rules.PNG


When you get the error click on Debug, and then go to Conditional Formatting -> Manage Rules and see if you have duplicate rules.

manage rules.png
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,582
Members
449,039
Latest member
Arbind kumar

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