Guest User

Untitled

a guest
Apr 24th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. Sub RangeColor()
  2. Dim aRnd(), rRng As Range
  3. Dim lVal As Long
  4. Dim i As Long, j As Long
  5. Application.Calculate
  6. lVal = Cells(3, 6).Value
  7.  
  8. If lVal > 0 Then
  9. ReDim aRnd(1 To 100)
  10. Randomize
  11.  
  12. For i = 1 To 100
  13. j = Int(Rnd * i + 1)
  14. If j <> i Then aRnd(i) = aRnd(j)
  15. aRnd(j) = i
  16. Next i
  17.  
  18. Set rRng = Cells(aRnd(1) + 1, 3)
  19.  
  20. For i = 2 To lVal
  21. Set rRng = Union(rRng, Cells(aRnd(i) + 1, 3))
  22. Next i
  23. End If
  24.  
  25. Application.ScreenUpdating = False
  26. Range("C2:C101").Interior.Color = RGB(200, 0, 0)
  27. If Not rRng Is Nothing Then rRng.Interior.Color = RGB(0, 200, 0)
  28. Application.ScreenUpdating = True
  29.  
  30. Set rRng = Nothing
  31. End Sub
Add Comment
Please, Sign In to add comment