LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Assigning a Variable to an Expression that Includes a Variable and VBA Property

hi,
mycolor is a variable and does not refer to myR.Font.index.
Insert the line "myR.Font.index=mycolor" before the "end sub"

you could also write

sub ChangeColor()
Range("D1:D10").Font.ColorIndex = IIf(Range("D1").Font.ColorIndex = 3, 4, 3)
end sub



"bluebird" a écrit dans le message de
...
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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
evaluation a variable in an expression [email protected] Excel Programming 5 June 6th 06 02:48 AM
Assigning a row to a variable Todd Excel Programming 4 June 10th 04 06:49 PM
How to specify a Range which includes an integer variable Hotbird[_3_] Excel Programming 4 May 7th 04 02:38 PM
Scope of variable includes all Form _and_ Code modules?? John Wirt[_2_] Excel Programming 5 August 18th 03 08:27 AM
variable not equal to expression steve Excel Programming 2 August 11th 03 07:05 PM


All times are GMT +1. The time now is 08:07 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"