VBA-Funktion Konvertierung einer LONG in RGB-Farben
Function Long2RGB(lColor As Long) As String
Dim iRed, iGreen, iBlue
' Convert Decimal Color Code to RGB
iRed = (lColor Mod 256)
iGreen = (lColor \ 256) Mod 256
iBlue = (lColor \ 65536) Mod 256
' Return RGB Code
Long2RGB = "(" & iRed & ", " & iGreen & ", " & iBlue & ")"
End Function
VBA-Funktion Konvertierung eines Hexadezimalwerts in RGB-Farben
Function Hex2RGB(hColor As String) As String
Dim iRed, iGreen, iBlue
' Convert HEx to RGB
hColor = Replace(hColor, "#", "") ' Hashtag entfernen
hColor = Right$("000000" & hColor, 6)
iBlue = Val("&H" & VBA.Mid(hColor, 1, 2))
iGreen = Val("&H" & VBA.Mid(hColor, 3, 2))
iRed = Val("&H" & VBA.Mid(hColor, 5, 2))
' Return RGB Code
Hex2RGB = "(" & iRed & ", " & iGreen & ", " & iBlue & ")"
End Function
VBA-Funktion Konvertierung einer LONG in Hexadezimalwert
Function Long2Hex(lColor As Long) As String
Dim hexCode As String
' Excel Formula to Convert Decimal to Hex
' =DEC2HEX(Decimal or Long Value)
' Convert Long to Hex code and Return
hexCode = Right$("000000" & Hex$(lColor), 6)
' Long2Hex = "#" & hexCode
Long2Hex = hexCode
End Function
VBA-Funktion Konvertierung von RGB-Farben in Hexadezimalwert
Function RGB2Hex(iRed As Integer, iGreen As Integer, iBlue As Integer) As String
Dim sHex As String
sHex = "#" & Right$("00" & Hex(iBlue), 2) _
& Right$("00" & Hex(iGreen), 2) _
& Right$("00" & Hex(iRed), 2)
RGB2Hex = sHex
End Function
VBA-Funktion Konvertierung von RGB-Farben in LONG
Function RGB2Long(iRed As Integer, iGreen As Integer, iBlue As Integer) As Long
RGB2Long = RGB(iRed, iGreen, iBlue)
End Function
VBA-Funktion Konvertierung eines Hexadezimalwerts in LONG
Function Hex2Long(hColor As String) As Long
' Convert Hex to Long
hColor = Replace(hColor, "#", "")
hColor = Right$("000000" & hColor, 6)
' Return Long Excel VBA Color Code
Hex2Long = Application.WorksheetFunction.Hex2Dec(hColor)
End Function
| Programmansicht |
![]() |
| Formelansicht |
![]() |

