UDF Warna RGB Cells

Sebuah User Defined Function untuk mendapatkan Nilai RGB dari warna Cells

Function getWarnaRGB(Rng As Range) As String
'-----------------------------------------
' Sctipt VBA    : 7a (Warna RGB A)
' Author        : https://vba.co.id
'                 Situs belajar VBA No.1
'                 di Indonesia
'-----------------------------------------
Dim hexColor As String
hexColor = Right("000000" & Hex(Rng.Interior.Color), 6)
getWarnaRGB = "RGB (" & CInt("&H" & Right(hexColor, 2)) & "," & _
                        CInt("&H" & Mid(hexColor, 3, 2)) & "," & _
                        CInt("&H" & Left(hexColor, 2)) & ")"
                    
End Function

Cara kedua

Function getWarnaRGB(Rng As Range) As String
'-----------------------------------------
' Sctipt VBA    : 7b (Warna RGB B)
' Author        : https://vba.co.id
'                 Situs belajar VBA No.1
'                 di Indonesia
'-----------------------------------------
Dim hexColor As Long
hexColor = Rng.Interior.Color
getWarnaRGB = "RGB (" & hexColor Mod 256 & "," & _
                        (hexColor \ 256) Mod 256 & "," & _
                        (hexColor \ 65536) & ")"
                    
End Function

Leave a Reply

Your email address will not be published. Required fields are marked *

Chat WhatsApp
WhatsApp