I need some help here, I need my macro to color each cell in a range, but each cell has to have a different color than the cell above. The code that I'm currently using does not perform that differentiation. The code is:
Function intRndColor()
'USE - FUNCTION TO PICK RANDOM COLOR, ALSO ALLOWS EXCLUSION OF COLORS YOU DON'T LIKE
Dim Again As Label
Dim RangeX As Range
Set RangeX = Range(Range("A1"), Range("A1").End(xlDown))
Again:
intRndColor = Int((50 * Rnd) + 1) 'GENERATE RANDOM IN
Select Case intRndColor
Case Is = 0, 1, 5, 9, 3, 13, 29, 30, 11, 21, 25, 29, 30, 32, 49, 51, 52, 55, 56 'COLORS YOU DON'T WANT
GoTo Again
Case Is = pubPrevColor
GoTo Again
End Select
pubPrevColor = intRndColor 'ASSIGN CURRENT COLOR TO PREV COLOR
' Range(Range("A1"), Range("A1").End(xlDown)).Interior.ColorIndex = pubPrevColor
For Each c In RangeX
c.Interior.ColorIndex = pubPrevColor
Next c
End Function
This code makes the whole range to be the same color, I don't get what I'm missing here...
You're picking a random colour correctly (albeit maxing out at 51). You're then just applying that one colour to all of your cells. You need to choose a random colour each time you apply it to a cell.
If you want to do it without using
GoToetc.A slightly tidier approach is to create a loop to apply the random colour and a function to generate the number: