Hello Everyone,
I have been searching and finally found something close to what I would like to do prior to asking you all. In post: http://www.excelforum.com/excel-prog...selection.html they did an excellent job selecting the random rows.
I need to take it one step further, I need the selected rows to be displayed on a new sheet. The idea being that I have a quiz with hundreds of questions and I only want a random selection to appear when I execute the macro. I plan on hiding the original questions and only displaying the randomly selected ones.
Thanks for your help in advance!
Here is the original code from the previous post.
Sub Random()
Dim arr As Variant
Dim nodupes As New Collection
Dim rng As Range
strr = "How many to select"
Do
noofcells = Application.InputBox(strr, Type:=1)
If noofcells > Selection.Cells.Count Then strr = "You must select a number less than " & Selection.Cells.Count + 1 & ". How many to select?"
Loop Until noofcells <= Selection.Cells.Count
ReDim arr(noofcells)
Do
On Error Resume Next
arr = Evaluate("=randbetween(1," & Selection.Cells.Count & ")")
nodupes.Add Item:=arr, Key:=CStr(arr)
On Error GoTo 0
Loop Until nodupes.Count = noofcells
If noofcells = 1 Then
Selection.Cells(nodupes(i)).Select
Else
Set rng = Selection.Cells(nodupes(1))
For i = 2 To noofcells
Set rng = Union(rng, Selection.Cells(nodupes(i)))
Next i
End If
rng.Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End Sub
Bookmarks