Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Consider this macro, which is supposed to toggle font color between
red (colorindex value = 3) and green (colorindex value =4). Put whatever values you like in range D1:D10. Sub ChangeColor() Dim myR as Range, mycolor as Variant Set myR = Range("D1:D10") mycolor = myR.Font.ColorIndex If mycolor = 3 Then mycolor = 4 ElseIf mycolor = 4 Then mycolor = 3 End If End Sub The macro fails to change the font color on the screen, but amazingly the macro does change color value, mycolor, from 3 to 4 and vice versa in the Immediate Window. If you revise the macro by substituting myR.Font.ColorIndex for the variable mycolor, the macro works fine. Is there a problem with assigning a variable to a VBA expression including properties like Font.ColorIndex? Has anyone ever found a reference that explains quirky situations like this one? Thank you. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
evaluation a variable in an expression | Excel Programming | |||
Assigning a row to a variable | Excel Programming | |||
How to specify a Range which includes an integer variable | Excel Programming | |||
Scope of variable includes all Form _and_ Code modules?? | Excel Programming | |||
variable not equal to expression | Excel Programming |