How to highlight a cell using the hex color value within the cell?

前端 未结 6 698
清歌不尽
清歌不尽 2020-11-30 04:02

I have a spreadsheet of symbols and matching hex colors. I want to fill the cell itself (or the one next to it) with the hex color within the cell. I\'ve read a bit about \"

6条回答
  •  感动是毒
    2020-11-30 05:03

    For this, a userform can be made with the Hex2Dec function.

    Function Hex2Dec(n1 As String) As Long
        Dim nl1 As Long
        Dim nGVal As Long
        Dim nSteper As Long
        Dim nCount As Long
        Dim x As Long
        Dim nVal As Long
        Dim Stepit As Long
        Dim hVal As String
    
        nl1 = Len(n1)
        nGVal = 0
        nSteper = 16
        nCount = 1
        For x = nl1 To 1 Step -1
           hVal = UCase(Mid$(n1, x, 1))
           Select Case hVal
             Case "A"
               nVal = 10
             Case "B"
               nVal = 11
             Case "C"
               nVal = 12
             Case "D"
               nVal = 13
             Case "E"
               nVal = 14
             Case "F"
               nVal = 15
             Case Else
               nVal = Val(hVal)
           End Select
           Stepit = (nSteper ^ (nCount - 1))
           nGVal = nGVal + nVal * Stepit
           nCount = nCount + 1
        Next x
        Hex2Dec = nGVal
    End Function
    ...
    UserForm1.TextBox1 = "RGB(" & Hex2Dec(UserForm1.txtHex1.Value) & "," & _
               Hex2Dec(UserForm1.txtHex2.Value) & "," & Hex2Dec(UserForm1.txtHex3.Value) & ")"
    

    For example ;the entered value to textbox: #FF8800 - Result : RGB(255,136,0)

提交回复
热议问题