Sub TestColor()
Dim OriginalColor As Long
OriginalColor = GetFontColor(Selection)
Dim RGB1 As String
RGB1 = RGB1 & ConvertLongToRGB(Selection.Font.Color, "R")
RGB1 = RGB1 & ", " & ConvertLongToRGB(Selection.Font.Color, "G")
RGB1 = RGB1 & ", " & ConvertLongToRGB(Selection.Font.Color, "B")
MsgBox (RGB1 & " Is the original color of selected cell - Long value of: " & OriginalColor)
Dim NewFontColor As Long
NewFontColor = ConvertRGBToLong(255, 0, 0)
SetFontColor Selection, NewFontColor
Dim RGB As String
RGB = RGB & ConvertLongToRGB(Selection.Font.Color, "R")
RGB = RGB & ", " & ConvertLongToRGB(Selection.Font.Color, "G")
RGB = RGB & ", " & ConvertLongToRGB(Selection.Font.Color, "B")
MsgBox (RGB & " Is the new color of selected cell - Long value of: " & NewFontColor)
MsgBox ("Now we will revert back to the way it was.")
SetFontColor Selection, OriginalColor
End Sub
Function SetFontColor(ByVal Target As Range, Col As Long) As Long
Target.Font.Color = Col
End Function
Function GetFontColor(ByVal Target As Range) As Long
GetFontColor = Target.Font.Color
End Function
Public Function ConvertRGBToLong(iRed As Integer, iGreen As Integer, iBlue As Integer) As Long
ConvertRGBToLong = RGB(iRed, iGreen, iBlue)
End Function
Public Function ConvertLongToRGB(lColor As Long, sRGB As String) As Integer
Select Case UCase(sRGB)
Case "R"
ConvertLongToRGB = lColor Mod 256
Case "G"
ConvertLongToRGB = lColor \ 2 ^ 8 Mod 256
Case "B"
ConvertLongToRGB = lColor \ 2 ^ 16 Mod 256
End Select
End Function