Dec-waarden converteren naar hex-waarden

RoVo1211

Gebruiker
Lid geworden
24 feb 2024
Berichten
86
Besturingssysteem
Windows 11
Office versie
Office 365
Schermafbeelding 2024-04-28 103135.png
Gegeven deze tabel, daar wil ik bij groenwaarden aan de linkerkant een kolom voor zetten met de hex-waarden en bij de blauw-waarden wil ik de hex-waarden erboven zetten in rij 5.
Vraag 1) zijn hex-waarden values of strings?
Vraag 2) Hoe krijg ik de hex-waarden in de tabel?

Ik ben al aan het stoeien geweest met de functie application.worksheetfunction.dec2hex, maar ik krijg het niet voor elkaar.
 

Bijlagen

  • Kleurentabel.zip
    51,4 KB · Weergaven: 6
Kijk hier eens naar:
Code:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'   Function            Color
'   Purpose             Determine the Background Color Of a Cell
'   @Param rng          Range to Determine Background Color of
'   @Param formatType   Default Value = 0
'                       0   Integer
'                       1   Hex
'                       2   RGB
'                       3   Excel Color Index
'   Usage               Color(A1)      -->   9507341
'                       Color(A1, 0)   -->   9507341
'                       Color(A1, 1)   -->   91120D
'                       Color(A1, 2)   -->   13, 18, 145
'                       Color(A1, 3)   -->   6
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function Color(rng As Range, Optional formatType As Integer = 0)     As Variant
    Dim colorVal As Variant
    colorVal = rng.Cells(1, 1).Interior.Color
    Select Case formatType
        Case 1
            Color = WorksheetFunction.Dec2Hex(colorVal, 6)
        Case 2
            Color = (colorVal Mod 256) & ", " & ((colorVal \ 256) Mod 256) & ", " & (colorVal \ 65536)
        Case 3
            Color = rng.Cells(1, 1).Interior.ColorIndex
        Case Else
            Color = colorVal
    End Select
End Function
 
Schermafbeelding 2024-04-28 120112.png

Bedankt Ahulpje, maar hoe integreer ik dit in mijn macro?
 
Onderstaande code toont de RBG waardes in HEX van cel E10:
Code:
Sub test()
   Color Cells(10, 5), 2
End Sub

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'   Function            Color
'   Purpose             Determine the Background Color Of a Cell
'   @Param rng          Range to Determine Background Color of
'   @Param formatType   Default Value = 0
'                       0   Integer
'                       1   Hex
'                       2   RGB
'                       3   Excel Color Index
'   Usage               Color(A1)      -->   9507341
'                       Color(A1, 0)   -->   9507341
'                       Color(A1, 1)   -->   91120D
'                       Color(A1, 2)   -->   13, 18, 145
'                       Color(A1, 3)   -->   6
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function Color(rng As Range, Optional formatType As Integer = 0) As Variant
    Dim colorVal As Variant
    colorVal = rng.Cells(1, 1).Interior.Color
    Select Case formatType
        Case 1
            Color = WorksheetFunction.Dec2Hex(colorVal, 6)
        Case 2
            Color = (colorVal Mod 256) & ", " & ((colorVal \ 256) Mod 256) & ", " & (colorVal \ 65536)
            MsgBox "Rood " & WorksheetFunction.Dec2Hex(colorVal Mod 256) & vbCrLf & _
            "Groen " & WorksheetFunction.Dec2Hex((colorVal \ 256) Mod 256) & vbCrLf & _
            "Blauw " & WorksheetFunction.Dec2Hex(colorVal \ 65536)
        Case 3
            Color = rng.Cells(1, 1).Interior.ColorIndex
        Case Else
            Color = colorVal
    End Select
End Function
 
Steun Ons

Nieuwste berichten

Terug
Bovenaan Onderaan