Attribute VB_Name = "RGB2Long" Option Explicit Function RGB2Long(Red As Long, Green As Long, Blue As Long, Optional RGB_String As String) As Long 'by Toby Erkson, 29Aug2006 'Converts a RGB color value to a long integer value. If a string is used the first three variables are ignored. 'Use 1: Call RGB2Long(215, 14, 255) 'Use 2: Call RGB2Long(215, 14, 255, "215, 14, 255") 'Spaces in string don't matter (if even used) and the first three values given are ignored. 'Thus Call RGB2Long(0, 0, 0, "215,14,255") returns the same result as Use 2. 'Note the string here Call RGB2Long(0, 0, 0, "0,0,") will be ignored since it contains < 5 characters. ' Dim sValues() As String If Len(RGB_String) > 4 Then 'Use string values instead of long values sValues = Split(RGB_String, ",") Red = Val(Trim(sValues(0))) Green = Val(Trim(sValues(1))) Blue = Val(Trim(sValues(2))) End If RGB2Long = (Red + ((Green * 256) + (Blue * 65536))) End Function 'Break down the Long color value into RGB values. Working with Excel colors sucks. 'Dim UseColorNum as Long 'Blue = Int(UseColorNum / 65536) 'Green = Int((UseColorNum - (65536 * lngBlue)) / 256) 'Red = UseColorNum - ((lngBlue * 65536) + (lngGreen * 256))