Hello the code i have selects 6 different cells randomly for rows 6 - 30. Once it has done this i want it to sum the rows individually, and it has to meet >=111 and <=170. If possible change the background color of the cell if it meets >=111 <+140
and a different cell fill color for >=141 to <=170.
Dim NumArr As Object, i As Long, j As Long, rng As Range, cell As Range
Application.ScreenUpdating = False
With Me
Set NumArr = CreateObject("System.Collections.ArrayList")
If .CboxHot.Value = "All" Then
Set rng = .Range("All")
ElseIf .CboxHot.Value = ("Cold Only") Then
Set rng = .Range("ColdNumbers")
ElseIf .CboxHot.Value = ("Cold + Hot") Then
Set rng = .Range("ColdHotNumbers")
ElseIf .CboxHot.Value = ("Hot Only") Then
Set rng = .Range("HotNumbers")
ElseIf .CboxHot.Value = ("Non Cold Or Hot") Then
Set rng = .Range("NonHotColdNumbers")
End If
If (.Shapes("MonOn").Visible = True) Or (.Shapes("WedOn").Visible = True) Or (.Shapes("SatOn").Visible = True) And .CboxHot.Value = "All" And .cboxodd.Value = 1 Then
'Set NumArr = CreateObject("System.Collections.ArrayList")
' Set rng = .Range("All")
For i = 6 To 30
NumArr.Clear
j = 1
Do Until j > 1
Set cell = RdmCell(rng)
' Consider only ODD numbers
If cell.Value Mod 2 = 1 Then
If Not cell.Value = "" And Not NumArr.contains(cell.Value) Then
NumArr.Add cell.Value
j = j + 1
End If
End If
Loop
Cells(i, 2).Resize(, 1) = NumArr.toarray
Next i
For i = 6 To 30
NumArr.Clear
j = 1
Do Until j > 5
Set cell = RdmCell(rng)
' Consider only Even numbers
If cell.Value Mod 2 = 0 Then
If Not cell.Value = "" And Not NumArr.contains(cell.Value) Then
NumArr.Add cell.Value
j = j + 1
End If
End If
Loop
Cells(i, 3).Resize(, 5) = NumArr.toarray
Next i
ElseIf (.Shapes("MonOn").Visible = True) Or (.Shapes("WedOn").Visible = True) Or (.Shapes("SatOn").Visible = True) And .CboxHot.Value = "All" And .cboxodd.Value = 2 Then
' Set NumArr = CreateObject("System.Collections.ArrayList")
'Set rng = .Range("All")
For i = 6 To 30
NumArr.Clear
j = 1
Do Until j > 2
Set cell = RdmCell(rng)
' Consider only ODD numbers
If cell.Value Mod 2 = 1 Then
If Not cell.Value = "" And Not NumArr.contains(cell.Value) Then
NumArr.Add cell.Value
j = j + 1
End If
End If
Loop
Cells(i, 2).Resize(, 2) = NumArr.toarray
Next i
For i = 6 To 30
NumArr.Clear
j = 1
Do Until j > 4
Set cell = RdmCell(rng)
' Consider only Even numbers
If cell.Value Mod 2 = 0 Then
If Not cell.Value = "" And Not NumArr.contains(cell.Value) Then
NumArr.Add cell.Value
j = j + 1
End If
End If
Loop
Cells(i, 4).Resize(, 4) = NumArr.toarray
Next i
Function RdmCell(rng As Range) As Range
Set RdmCell = rng.Cells(Int(Rnd * rng.Cells.Count) + 1)
End Function
Thank you for any help
Bookmarks