Clear cell contents if Conditional Formatting is applied to it

zero269

Board Regular
Joined
Jan 16, 2023
Messages
219
Office Version
  1. 365
Platform
  1. Windows
Hello,

I'm trying to use this VBA code that claims to be able to clear a cells contents if conditional formatting has been applied to a cell.
Code from that thread:
VBA Code:
Public Sub DeleteHighlighted()
Set rng = Selection
For Each c In rng
        If c.FomratCondition = True Then
           c.Clear
        Else
        End If
    Next c
End Sub
When I try to use the code as is, it throws a compiling error:
1674970908760.png

This code was written in 2004 so I can only assume that the Syntax has changed since then.

I'm basically trying to clear the contents from the active cell if conditional formatting has been applied to it.

I often build a list of Quiz numbers into a column. If it's a duplicate within the column, the cell will highlight Red. If it's a duplicate in the Master List located on another Sheet, it will highlight Orange.
I often just delete the cell contents once I see it's a duplicate, but I'd like to automate the process so that once I paste the value, it will automatically be cleared once the CF has been applied.
I'll know it's a duplicate when I see that the cell remains clear after pasting my value and hitting Enter.
 
All of the above discussion (& your other thread) seems that a large part (if not all) of the problem centres around the conditional formatting being removed if values are pasted. It brings me back to the questions I asked above. What is your response to them?
As I understand it, that would mean if a cell gets highlighted you delete the cell contents. I presume that means that the colour goes away?
That is, every time a cell gets coloured, it gets un-coloured straight away because of the deletion.
If that is so, what was the point of applying the conditional formatting in the first place?
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,214,979
Messages
6,122,557
Members
449,088
Latest member
davidcom

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