one shortcut key to produce two colors


Posted by Jun on February 11, 2002 3:12 PM

I would like to build a short cut key say ctrl-w to do the following:

at the first stroke, the cell turns blue, second stroke, the color turns black. essentially, ctrl-w then give me two colors I can apply quickly. much like the ctrl-B key.

any comments/solutions are welcome.

Posted by Derek on February 11, 2002 4:40 PM

Jun
Use this macro code and assign a short cut key to it:
If Selection.Interior.ColorIndex = 8 Then Selection.Interior.ColorIndex = 1 Else Selection.Interior.ColorIndex = 8
End Sub
Derek

Posted by Derek on February 11, 2002 5:08 PM

Re: why restrict yourself to two colors?

If you use code like this you can have as many colours as you want.

If Selection.Interior.ColorIndex = xlNone Then
Selection.Interior.ColorIndex = 8
Else
If Selection.Interior.ColorIndex = 8 Then
Selection.Interior.ColorIndex = 1
Else
If Selection.Interior.ColorIndex = 1 Then
Selection.Interior.ColorIndex = 3
Else
If Selection.Interior.ColorIndex = 3 Then
Selection.Interior.ColorIndex = 5
Else
If Selection.Interior.ColorIndex = 5 Then
Selection.Interior.ColorIndex = 9
Else
If Selection.Interior.ColorIndex = 9 Then
Selection.Interior.ColorIndex = 4
Else
If Selection.Interior.ColorIndex = 4 Then
Selection.Interior.ColorIndex = xlNone
Else
Selection.Interior.ColorIndex = xlNone
End If
End If
End If
End If
End If
End If
End If
End Sub

Posted by Mark W. on February 11, 2002 5:23 PM

I trust that you know...

...that the Fill Color palette can be detached
(click and drag) from the Fill Color toolbar.
Once detached it can float above your worksheet
allowing you to apply colors at will.



Posted by Jun on February 12, 2002 7:42 AM

Re: why restrict yourself to two colors?--thanks,


Derek:

the code works out very nicely. Thanks a lot. What is the definition of xlNone? In fact, I want to expand this beyond colors. say number format--I want to toggle between say 4 formats. what is the equivalent of "xlNone" there? also, how do you like the idea of using "select case statements" to toggle these? thanks again,

Jun

: I would like to build a short cut key say ctrl-w to do the following: