System Information
Windows
Edition Windows 10 Home
Version 22H2
Installed on 12/16/2023
OS build 19045.5965
Experience Windows Feature Experience Pack 1000.19061.1000.0
Microsoft 365
Microsoft® Excel® for Microsoft 365 MSO (Version 2505 Build 16.0.18827.20102) 64-bit
Microsoft® Access® for Microsoft 365 MSO (Version 2505 Build 16.0.18827.20102) 64-bit
Summary
I've tested this on Excel and Access, with the same result. A call to the RGB function in the VBA library returns an incorrect result. The function appears to invert the red and blue values. This can be recreated with the code below.
Code Example
Public Sub sbTestRGB()
Dim lngColor As Long
Dim intRed As Integer
Dim intGreen As Integer
Dim intBlue As Integer
intRed = 100
intGreen = 255
intBlue = 200
Debug.Print "Hex Red: " & Hex(intRed)
Debug.Print "Hex Green: " & Hex(intGreen)
Debug.Print "Hex Blue: " & Hex(intBlue)
Debug.Print "Combined Hex: " & Hex(intRed) & Hex(intGreen) & Hex(intBlue)
Debug.Print "Hex to Long: " & CLng("&h" & Hex(intRed) & Hex(intGreen) & Hex(intBlue))
lngColor = RGB(intRed, intGreen, intBlue)
Debug.Print "Result from RGB function: " & lngColor
Debug.Print "Long to Hex: " & Hex(lngColor)
End Sub
Code Result
On my system the result is as follows. Note that when the long value from the RGB function is converted back to hex, the result has the red and blue values inverted compared with the original hex values.
Hex Red: 64
Hex Green: FF
Hex Blue: C8
Combined Hex: 64FFC8
Hex to Long: 6619080
Result from RGB function: 13172580
Long to Hex: C8FF64
Note that an online RGB calculator verifies that the correct numeric value for these RGB values is 6619080. An online calculator also verifies that with an input number of 13172580 (the result from the RGB function), the red value is 200, green is 255, and blue is 100.