View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Joe Kavanagh Joe Kavanagh is offline
external usenet poster
 
Posts: 1
Default newbie question (random colours)

Hi Sara-Jane

You can use the Rnd function to generate a random integer and the
ColorIndex property to set the cells interior color. The ColorIndex
property can also be used to set a cells border and font color.

The following code sets the interior color of cell A1.

Sub randomColor()
Dim value as Integer
Randomize ' Initialize random-number generator.

' Generate random value between 1 and 56.
' The default color palette has 56 colors.
value = Int((56 * Rnd) + 1)

Range("A1").Interior.ColorIndex = value
End Sub

Joe.

"Sara-Jane" wrote in message ...
Hello, can anyone help me, at the end of my macro, I need to put a random
colour into a cell in an excel.

How can I do this?

Thanks