Try something like
Sub AAA()
Dim Colors As Variant
Dim N As Long
Dim C As Long
Colors = Array(3, 4, 5, 6, 29)
For N = 1 To 10
C = Colors(Int((UBound(Colors) - LBound(Colors) + 1) * _
Rnd + LBound(Colors)))
Cells(N, 1).Interior.ColorIndex = C
Next N
End Sub
Change the values within the Array function to the color index values
you want to choose from. The code within the loop picks a random value
from the values within the Colors array and assigns it to a cell.
Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
On Sun, 23 May 2010 19:35:03 -0700, honeybee129
<(E-Mail Removed)> wrote:
>This works if you just want a random color of the first 5 colors in the color
>index list, but if I wanted a radom color out of a specific 5 colors how
>could I adapt this? The 5 color indexes I want are: 3,4,5,6, and 29.
>
>"N10" wrote:
>
>>
>> "Casey" <(E-Mail Removed)> wrote in message
>> news:C7BC972D-1688-44A1-97AA-(E-Mail Removed)...
>> >I am trying to fill a grid of equal sized cells with random colors, or
>> >colors
>> > attached to a random number. I can fill the grid with random numbers
>> > easily
>> > enough, it's the colors i want.
>> > Thanx....Casey
>>
>>
>> Hi Casey
>>
>> Try this then adpat to your needs
>>
>>
>> Sub colorit()
>>
>>
>> Dim task As Range
>> Dim myvalue
>> Set task = Range("A1:l32")
>>
>>
>> For y = 1 To 5
>>
>> For Each Cell In task
>> Randomize
>>
>> myvalue = Int((56 * Rnd) + 1)
>>
>> Cell.Interior.ColorIndex = myvalue
>>
>> Next
>>
>> Next
>>
>> '
>> End Sub
>>
>>
>>