' ----------------------------------------------------------------
' Procedure Name: f_getRGBCellBackground
' Purpose: get the RGB value of a cell background color
' ----------------------------------------------------------------
Function f_getRGBCellBackground(cell As Range, Optional partialColor As String) As Variant
Dim backGroundColor As Long
Dim red As Long
Dim green As Long
Dim blue As Long
backGroundColor = cell.Interior.Color
red = backGroundColor Mod 256
green = backGroundColor \ 256 Mod 256
blue = backGroundColor \ 65536 Mod 256
If partialColor <> vbNullString Then
Select Case partialColor
Case "red"
f_getRGBCellBackground = CLng(red)
Case "green"
f_getRGBCellBackground = CLng(green)
Case "blue"
f_getRGBCellBackground = CLng(blue)
Case Else
f_getRGBCellBackground = "error in parameter"
End Select
Else
f_getRGBCellBackground = Right("000" & red, 3) & " | " & Right("000" & green, 3) & " | " & Right("000" & blue, 3)
End If
End Function
Comments
0 B
|0 👍
/0 👎
0 B
|👍
/👎