Among the ways to use user-defined functions in MSOffice's Excel (2021 version), I would like to change the cell color using the source below. However, I am inquiring because it is not working, so I would appreciate it if you could tell me a solution.
(User-defined function source)
Option Explicit
--------------------------------------------------------------------------
Function FCOLOR(sHex, srng As Range) As String
Dim sr As Long: Dim sb As Long: Dim sg As Long
sHex = CStr(svRng(sHex)) 'CStr 정수를 문자열로
sHex = Replace(sHex, "#", "")
sHex = Right("000000" & sHex, 6)
sr = Val("&H" & Left(sHex, 2))
sg = Val("&H" & Mid(sHex, 3, 2))
sb = Val("&H" & Right(sHex, 2))
srng.Interior.Color = RGB(sr, sg, sb)
FCOLOR = srng.Address(0, 0) & " = (" & sr & "," & sg & "," & sb & ")"
End Function
--------------------------------------------------------------------------
Function svRng(TargetRng)
If TypeName(TargetRng) = "Range" Then
svRng = TargetRng.Value
Else
svRng = TargetRng
End If
End Function