It’s been so long since I’ve tried to do anything in BASIC.
I am trying to write a function that given three values for red, green, blue, will set the calling cell’s background to that color and then return that color as #rrggbb in the cell. Whenever I update the function call with a value or a cell address, I always get a very generic looking dialog that gives no indication WHERE the error is occurring
BASIC runtime error.
Object variable not set.
When I set a breakpoint on the function declaration itself, I can see the arguments in the Calls pane of the IDE, and then when I click Step Into, I immediately get the error dialog. I can’t understand what the problem is
Function ApplyBackgroundColor(Raddr As Variant, Gaddr As Variant, Baddr As Variant) as String
dim Rval As Long
dim Gval As Long
dim Bval As Long
if IsNumeric(Raddr) Then
Rval = Raddr
else
Rval = Raddr.Value
end if
if IsNumeric(Gaddr) Then
Gval = Gaddr
else
Gval = Gaddr.Value
end if
if IsNumeric(Baddr) Then
Bval = Baddr
else
Bval = Baddr.Value
end if
Application.Caller.CellBackColor = rgb(Rval,Gval,Bval)
ApplyBackgroundColor = "#" & Right(Hex(Rval),2) & Right(Hex(Gval),2) & Right(Hex(Bval),2)
End Function