• 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.

choose cell color

kds14589

New Member
I did this sometime ago but I can't find the old VBA I used in some of the old backups I keep while 'designing' a Excel workbook
My worksheet is called General_Misc
In cell W4 I put RED
In cell X4 I put GREEN
In cell Y4 I put BLUE
In cells W5:Y150 are validation data listboxes so I can choose any number between 0-255, with a default value of 0, these validation listboxes do not display unless there is a value in U5:U150
Starting in cell Z5 I wish the cell to display the interior.colorindex for the numbers that I've chosen from W5,X5,Y5.
 
suggest you upload a sample worksheet that we can work with. I don't wish to recreate your worksheet to solve your issue. Help to help you by making it easy for us to provide you with a solution since you already have a worksheet with data.
 
i'm unsure if this is what you need so I'm sending the whole thing it's on worksheet General_Misc
here's a pix to 75886
 

Attachments

  • 8.16.21 TEST Cards v4 .xlsm
    249.6 KB · Views: 2
suggest you upload a sample worksheet that we can work with. I don't wish to recreate your worksheet to solve your issue. Help to help you by making it easy for us to provide you with a solution since you already have a worksheet with data.


AlanSidman
I realized that my original post thinking is faster than my worksheet overhaul. That worksheet is referencing Color_chart which I download the code from dmcritchie.mvps.org/excel/colors.htm
That worksheet W,X,Y are index/match to Color_chart
If cell z can display the RGB color that goes with those numbers that will work too.
 
On your tab Color Chart, change the values in Column G to the actual index number and not include the word color. Then in your drop down where you were selecting the color change the inputs to just the number. Then the following will populate column Z as you requested.
Code:
Option Explicit

Sub KDS()
    Dim i As Long
    Dim lr As Long
    lr = Range("R" & Rows.Count).End(xlUp).Row
    For i = 5 To lr
        Range("Z" & i).Interior.ColorIndex = Range("T" & i)
    Next i
End Sub
 
On your tab Color Chart, change the values in Column G to the actual index number and not include the word color. Then in your drop down where you were selecting the color change the inputs to just the number. Then the following will populate column Z as you requested.
Code:
Option Explicit

Sub KDS()
    Dim i As Long
    Dim lr As Long
    lr = Range("R" & Rows.Count).End(xlUp).Row
    For i = 5 To lr
        Range("Z" & i).Interior.ColorIndex = Range("T" & i)
    Next i
End Sub

I tried and it works THANKS
 
Or if you want to use your RGB figures.
Code:
Sub Color_RGB()
Dim i As Long
    For i = 5 To Cells(Rows.Count, 18).End(xlUp).Row
        With Cells(i, 26)
            .Interior.Color = RGB(.Offset(, -3).Value, .Offset(, -2).Value, .Offset(, -1).Value)
        End With
    Next i
End Sub
 
Back
Top