Sub Get10RandomValuesWithCondition()
Dim HowMany As Long, Cnt As Long, RandomIndex As Long, Tmp As Variant, Arr As Variant
[B][COLOR="#0000FF"]HowMany = 10[/COLOR][/B]
Arr = Split(Application.Trim(Join(Application.Transpose(Evaluate("IF(" & Range("C2", Cells(Rows.Count, "C").End(xlUp)).Address & "< E1," & Range("A2", Cells(Rows.Count, "A").End(xlUp)).Address & ","""")")))))
Randomize
For Cnt = UBound(Arr) To LBound(Arr) Step -1
RandomIndex = Int((Cnt - LBound(Arr) + 1) * Rnd + LBound(Arr))
Tmp = Arr(RandomIndex)
Arr(RandomIndex) = Arr(Cnt)
Arr(Cnt) = Tmp
Next
For Cnt = 1 To HowMany
Range("[B][COLOR="#FF0000"]F1[/COLOR][/B]").Resize(HowMany) = Application.Transpose(Arr)
Next
End Sub
A | B | C | D | E | F | |
---|---|---|---|---|---|---|
1 | Values | 10 | List | |||
2 | Amy | 1 | June | |||
3 | Beth | 2 | Cal | |||
4 | Cal | 7 | Oscar | |||
5 | Don | 9 | Beth | |||
6 | Erin | 2 | Iris | |||
7 | Faye | 11 | Don | |||
8 | Greg | 13 | Nadia | |||
9 | Hank | 17 | Don | |||
10 | Iris | 5 | Paul | |||
11 | June | 4 | Tonya | |||
12 | Kevin | 22 | ||||
13 | Lou | 18 | ||||
14 | Maria | 4 | ||||
15 | Nadia | 7 | ||||
16 | Oscar | 8 | ||||
17 | Paul | 9 | ||||
18 | Don | 44 | ||||
19 | Don | 4 | ||||
20 | Sandy | 2 | ||||
21 | Tonya | 1 | ||||
22 |
Array Formulas
<thead> </thead><tbody> </tbody> Note: Do not try and enter the {} manually yourself |
=IFERROR(INDEX(Sheet3!A:A,SMALL(IF(Sheet3!$A$2:$A$30<>"",IF(Sheet3!$C$2:$C$30<Sheet3!$E$1,IF(COUNTIFS(Sheet3!$A$2:$A$30,Sheet3!$A$2:$A$30,Sheet3!$C$2:$C$30,"<"&Sheet3!$E$1)>COUNTIF($F$1:$F1,Sheet3!$A$2:$A$30),ROW(Sheet3!$A$2:$A$30)))),RANDBETWEEN(1,COUNTIFS(Sheet3!$A$2:$A$30,"*?",Sheet3!$C$2:$C$30,"<"&Sheet3!$E$1)-ROW($F2)+ROW($F$1)+1))),"")