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

前端 未结 6 699
清歌不尽
清歌不尽 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 04:42

    This is another option - it updates the cell color when you select the cell assuming the value in the cell starts with "#" and is 7 characters.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
      If (Left(ActiveCell.Text, 1) = "#" And Len(ActiveCell.Text) = 7) Then
        ActiveCell.Interior.Color = WorksheetFunction.Hex2Dec(Mid$(ActiveCell.Text, 2))
    End If
    
    End Sub
    

提交回复
热议问题