rotate highlighting colors macro

P

pwilson.bowdoin

I need to create a macro that when pressed will cycle through a number
of highlighting colors.

So for example when I press the shortcut the first time it will change
to yellow, a second time change to red, a third time to grey etc. etc.
etc.

I'm sure this is relatively basic, but I really need the help. Thanks
so much!
 
D

Don Guillett

A couple of ideas to play with. Right click sheet tab>view code>insert
all>play.

Public num'top line of sheet module
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Target.Interior.ColorIndex = num
num = num + 1
End Sub

'Private Sub Worksheet_SelectionChange(ByVal Target As Range)
''num = 1
'Select Case num
'Case 1: x = 10
'Case 2: x = 4
'Case 3: x = 6
'Case Else
'End Select
'Target.Interior.ColorIndex = x
'num = num + 1
'End Sub


Sub startover()
num = 1
End Sub
 
R

Rick Rothstein \(MVP - VB\)

Something like this should do what you want...

Dim NewColor As Long
Static LastColor As Long
Do
NewColor = RGB(256 * Rnd, 256 * Rnd, 256 * Rnd)
Loop Until NewColor <> LastColor
LastColor = NewColor
Range("D4:F10").Cells.Interior.Color = NewColor

Just so you know what is going on, the loop is there to make sure the last
color used is not repeated. Set the range of cells whose color you want to
change in the Range statement at the bottom of the code.

Rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top