Coloring cells in Excel with CMYK cell values
Question
I'm looking for a way possibly using VBA to apply a cell's fill value by looking at specified fields in the same record. This would be a sample tab delimited Excel sheet:
BEGIN_DATA_FORMAT
SampleID SAMPLE_NAME CMYK_C CMYK_M CMYK_Y CMYK_K LAB_L LAB_A LAB_B
BEGIN_DATA
1 1 100 0 0 60 34.16 -19.52 -27.46
2 2 100 100 0 60 22.02 6.27 -23.25
3 3 100 0 0 0 54.56 -31.12 -45.29
END_DATA
Fields 3-6 each contain the values for CMYK respectively. I'd like to apply a cell background fill to field 1 by parsing each record for the combined CMYK values as a starting point.
Conversion to RGB or HSL may need to be done initially unless there's a backdoor method to set CMYK values in the Excel/Windows color picker.
Solution
this will give you the RGB from the CYMK in your data:
Function CYMK2RGB(c As Integer, y As Integer, m As Integer, k As Integer) As Long
Dim R As Integer
Dim G As Integer
Dim B As Integer
Dim colors As Integer
colors = 255 * (100 - k) / 100
R = colors * (100 - c) / 100
G = colors * (100 - m) / 100
B = colors * (100 - y) / 100
CYMK2RGB = RGB(R, G, B)
End Function
using range("A1").Interior.Color=cymk2rgb(...)
will set the color - note it's not going to be an exact match, as CYMK is subtractive, and RGB is additive. this site: http://www.printernational.org/rgb-versus-cmyk.php has more details comparing the two.