I'm looking to store an RGB colour in a variable in an Excel VBA project, to set the background color of various cell/ranges throughout a sub.
I want to set the colour once in a variable, so if I decide to change it throughout I only need to do it in one place.
Dim clrBlue As ColorFormat
clrBlue = RGB(0, 0, 256)
Range("a2").Interior.Color = clrBlue
Range("b3").Interior.Color = clrBlue
With the above code, I'm getting runtime error:
Object variable or With block variable not set
I could write separate functions (SetBlue
, SetRed
, SetGreen
) to apply each colour, but that feels messy.
Can anyone suggest what I'm doing wrong?