• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Color identification in excel

SAN04

Member
Hello all,

I need to assign particular number (1,2,3&4) based on the color in particular cell. Example if cell is colored yellow, the number 1 should come in cell, if cell is colored red, the number 2 should come in the cell.

Please suggest formula for the same.

Regards
Sanjay Dixit
 

SAN04

Member
Thanks Vletm.

Please tell how you did that else I have to further use various colors and numbers.
 

vletm

Excel Ninja
SAN04
Check that code.
Add there more case's as You would like...
Code:
            Select Case .Interior.Color
                Case 65535
                    c = 1
                Case 255
                    c = 2
                Case 5287936
                    c = 3
                Case 15773696
                    c = 4
            End Select
 

SAN04

Member
Thanks Vltem. Please tell how this value against is calculated. In case i use now brown color what will be the value.
 

shili12

Member
@SAN04
I researched that but the best i could do for you to get a brown colour is use this:-
and then change code as desired
Determining the RGB Value of a Color

and they gave this function :-
Code:
Function getRGB3(rcell As Range, Optional opt As Integer) As Long
    Dim C As Long
    Dim R As Long
    Dim G As Long
    Dim B As Long

    C = rcell.Interior.Color
    R = C Mod 256
    G = C \ 256 Mod 256
    B = C \ 65536 Mod 256

    If opt = 1 Then
        getRGB3 = R
    ElseIf opt = 2 Then
        getRGB3 = G
    ElseIf opt = 3 Then
        getRGB3 = B
    Else
        getRGB3 = C
    End If
End Function
 

Attachments

Last edited:

vletm

Excel Ninja
SAN04
There is none that kind of formula ...
Application.StatusBar = ActiveCell.Interior.Color

If You would like to solve those ... then ... eg
Get RGB-values
Screenshot 2022-09-08 at 17.59.02.png
and
calculate that value with below
Code:
Function xlfRGB2DecX(Red As Integer, Green As Integer, Blue As Integer) As Long
    xlfRGB2DecX = Red * 256 ^ 0 + Green * 256 ^ 1 + Blue * 256 ^ 2
End Function
 
Top