Excel formula that prints cell color (ColorIndex or RGB)

后端 未结 3 875
没有蜡笔的小新
没有蜡笔的小新 2020-12-18 12:30

Is there, in Excel, a Formula that retrieve the ColorIndex (or RGB) of a cell?

I found the follwing function:

CELL(info_type, the_cell)
3条回答
  •  不知归路
    2020-12-18 13:08

    The following function will display the RGB value of a selected cell.

    Function CellColorValue(CellLocation As Range)
        Dim sColor As String
    
        Application.Volatile
        'Retrieve hex value into string sColor    
        sColor = Right("000000" & Hex(CellLocation.Interior.Color), 6)
        'Return the string Version e.g. 255,255,255 RGB color value found in 
        'Excel cell. Use in built worksheet function to convert Hex to Decimal
        'Use string function to separate Hex string into three parts
        CellColorValue = Application.WorksheetFunction.Hex2Dec(Right(sColor, 2)) & "," & application.WorksheetFunction.Hex2Dec(Mid(sColor, 3, 2)) & "," & Application.WorksheetFunction.Hex2Dec(Left(sColor, 2))
    End Function
    

提交回复
热议问题