G
Guest
Guest
I need to select 20 questions from a group of 100. It needs to be random and none repeating.
Any suggestions?
Thanks
Any suggestions?
Thanks
Option Explicit
Private upr As Integer
Private lwr As Integer
Sub Ran()
Dim cell As Range
upr = 100 'upper integer limit
lwr = 1 'lower integer limit
Application.ScreenUpdating = False
[a1:a20].Select
For Each cell In Selection
Randomize
ActiveCell = Int((upr - lwr + 1) * Rnd + lwr)
Call tstdup
ActiveCell.Offset(1, 0).Select
Next cell
[a1].Select
Application.ScreenUpdating = True
End Sub
Private Sub tstdup()
Dim LastRow As Integer
Dim c As Range
Dim myrng As Range
Dim SearchValue As String
LastRow = ActiveCell.Row - 1
If LastRow = 0 Then Exit Sub
Set myrng = Range("a1:a" & LastRow)
SearchValue = ActiveCell.Value
With Range("A1:A" & LastRow)
Set c = .Find(what:=SearchValue, LookIn:=xlValues, lookat:=xlWhole)
End With
If Not c Is Nothing Then
ActiveCell = Int((upr - lwr + 1) * Rnd + lwr)
Call tstdup
End If
Set myrng = Nothing
Set c = Nothing
End Sub