Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub RangeColor()
- Dim aRnd(), rRng As Range
- Dim lVal As Long
- Dim i As Long, j As Long
- Application.Calculate
- lVal = Cells(3, 6).Value
- If lVal > 0 Then
- ReDim aRnd(1 To 100)
- Randomize
- For i = 1 To 100
- j = Int(Rnd * i + 1)
- If j <> i Then aRnd(i) = aRnd(j)
- aRnd(j) = i
- Next i
- Set rRng = Cells(aRnd(1) + 1, 3)
- For i = 2 To lVal
- Set rRng = Union(rRng, Cells(aRnd(i) + 1, 3))
- Next i
- End If
- Application.ScreenUpdating = False
- Range("C2:C101").Interior.Color = RGB(200, 0, 0)
- If Not rRng Is Nothing Then rRng.Interior.Color = RGB(0, 200, 0)
- Application.ScreenUpdating = True
- Set rRng = Nothing
- End Sub
Add Comment
Please, Sign In to add comment