Forum

Identify cell color...
 
Notifications
Clear all

Identify cell color from conditional formatting

9 Posts
3 Users
0 Reactions
363 Views
(@bobkap)
Posts: 17
Eminent Member
Topic starter
 
This code does not work.  I need to identify those  cells that are NOT red in the a column and then delete the whole row.  Then, I need to remove the red color.
 
'Delete cells with no red color
email = Application.match("email", Range("1:1"), 0)
finalrow = Cells(Rows.Count, 1).End(xlUp).Row
For counter3 = finalrow To 1 Step -1
If Cells(counter3, email).Interior.ColorIndex <> RGB(255, 0, 0) Then
Rows(counter3).Delete
End If
Next counter3
 
Posted : 09/09/2020 11:51 pm
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi Bob,

Use DisplayFormat.Interior.Color to get the color set by CF e.g.

Debug.Print Range("A1").DisplayFormat.Interior.Color

see attached file for some examples with CF rules set.

Regards

Phil

 
Posted : 10/09/2020 12:31 am
(@bobkap)
Posts: 17
Eminent Member
Topic starter
 

Thanks very much Phil.  If you don't mind, can you please explain a bit about what "debug.print" is used for?  I have tried to read about and understand that but I just cannot seem to figure it out.

 

Regards,

Bob Kaplan

 
Posted : 11/09/2020 12:54 pm
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi Bob,

Debug.Print prints information to the Immediate Window in the VBA Editor/Debugger.  So Debug.Print Range("A1").DisplayFormat.Interior.Color prints the value of the DisplayFormat Interior Color of A1.

You can read about debugging and Debug.Print here

Debugging VBA

More Tips on Debugging VBA

Regards

Phil

 
Posted : 11/09/2020 6:35 pm
(@bobkap)
Posts: 17
Eminent Member
Topic starter
 

Hi Phil,

I just cannot get this to work.  Maybe, I didn't input your suggestion correctly?  When I run this macro it deletes ALL rows regardless of the color of the cell in column #3.

Can you please review and let me know where I'm going wrong?

Thanks,

Bob

 
Posted : 12/09/2020 8:25 pm
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi Bob,

Please attach your file for me to check.

Thanks

Phil

 
Posted : 12/09/2020 8:48 pm
(@bobkap)
Posts: 17
Eminent Member
Topic starter
 

Whoops....I meant to.  Here it is. 

 
Posted : 12/09/2020 9:11 pm
(@purfleet)
Posts: 412
Reputable Member
 

Just had a quick check and i think it is a combination of missing the displayformat & using colorindex rather than color

This deletes the red cells

Cells(counter3, email).DisplayFormat.Interior.Color = RGB(255, 0, 0)

but you had

Cells(counter3, email).Interior.ColorIndex = RGB(255, 0, 0)

 
Posted : 12/09/2020 11:30 pm
(@bobkap)
Posts: 17
Eminent Member
Topic starter
 

Thanks. I will try that.

 
Posted : 12/09/2020 11:35 pm
Share: