marreco
Well-known Member
- Joined
- Jan 1, 2011
- Messages
- 609
- Office Version
- 2010
- Platform
- Windows
Hi.I have in column 'A' an amount of numbers per line.
I would like to generate column 'B' only 15 numbers without repeating.
example:
I have in column 'A' 50 different numbers.
necessary that in column 'B' is generated from the draw 15 numbers without repetition.
I could not adapt that code
I would like to generate column 'B' only 15 numbers without repeating.
example:
I have in column 'A' 50 different numbers.
necessary that in column 'B' is generated from the draw 15 numbers without repetition.
I could not adapt that code
Code:
Sub randomCollection()
Dim Names As New Collection
Dim lastRow As Long, i As Long, j As Long, lin As Long
Dim wk As Worksheet
Set wk = Sheets("Plan1")
With wk
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
For i = 2 To lastRow
Names.Add wk.Cells(i, 1).Value, CStr(wk.Cells(i, 1).Value)
Next i
lin = 1
For i = lastRow - 1 To 1 Step -1
j = Application.WorksheetFunction.RandBetween(1, i)
lin = lin + 1
Range("B" & lin) = Names(j)
Names.Remove j
Next i
End Sub