Get Excel cell background color hex value
excel, vba
Solution
try this
Function HexCode(Cell As Range) As String
HexCode = Right("000000" & Hex(Cell.Interior.Color), 6)
End Function
Problem
I would like to obtain the background color of a cell in an Excel sheet using a UDF formula or VBA. I found this UDF: ``` Public Function BColor(r As Range) As Long BColor = r(1).Interior.ColorIndex End Function ``` It can be used like this in a cell: `=BColor(A1)` I'm not familiar with VBA, this returns some long value and I wonder if it is possible to obtain the hex value directly. Thank you!