Comparing RGB Values

kevinsamuelabraham

New Member
Joined
Jun 26, 2011
Messages
8
Hi ,

I am Kevin, a newbie both to the forum and Excel Macro coding. I work with Excel 2007 on Windows XP.

I have a worksheet with conditional formatting. It highlights cells with duplicate values with RED as the background color. Once the data has been entered, I will have to perform certain processing for the duplicate records.

To do this I am parsing all the cells from left to right and top to bottom. While doing that, I would like to check the background color of the cell. If the background color is (255,0,0) then I would like to do some processing ...

Something to the effect of

Set sh3 = Sheets("Assignments")
If (sh3.Cells(row, column).Interior.Color = RGB(255, 0, 0)) Then
<Processing>
End If

but this doesn't seem to work. So could you please let me know how to alter this funtion to make it work, or if there is any other funtion that I should be using to get this task completed.

Please let me know if you need further clarification on the problem.

I look forward to hearing from people on this and I really appreciate you taking time to help me out with this.

Thanks and I hope you had a great weekend !


Cheers,
KeV !
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
If you test the .Interior.Color of a cell, it will not detect a cell whose color has been set by Conditional Formatting.

It would be better to test for the condition that set the format.
 
Upvote 0
The conditional formatting is to find and highlight duplicates column wise. I thought it would take quite a bit of coding effort to do that and hence used conditional formatting to highlight them..

Any other way/functions in which I could get to background color set by Conditional Formatting ?
If I can never get to the background color then would I be able to use other methods like changing the font type/size or anything of that sort ?

Thank you so much for such a quick reply ! :)


Cheers,
KeV !
 
Upvote 0
Code:
... sh3.Cells(row, column).Interior.ColorIndex = 3 ...
 
Upvote 0
instead of
Code:
If (sh3.Cells(row, column).Interior.Color = RGB(255, 0, 0)) Then
    Rem code
End If
use
Code:
With sh3
    If Application.CountIf(.Columns(column), .Cells(row, column)) > 1 Then
        Rem code
    End If
End With
Also row and column are risky choices for variable names, since they are also names of properties of a worksheet.
 
Upvote 0
My priorities got a little shifted and hence I couldn't get to this till now.

That single line of code, worked like a charm sir ! Thank you so very much :biggrin:

I although I still do not understand the semantics of it, it was just what I was looking for !

Thank you very much for your time and sharing your expertise :)


Cheers,
KeV !
 
Upvote 0

Forum statistics

Threads
1,224,596
Messages
6,179,807
Members
452,944
Latest member
2558216095

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