我正在研究一个宏,它为随机测试选择随机系列的员工ID号.我运行的代码很好,除了返回的第一个数字总是相同的.例如,如果我的ID号是1-100并且我想要10个随机数,则第一个数字将始终为1,然后在此之后随机.
作为一项额外的挑战,是否有可能在列表循环之前选择相同的数字?
这是我正在使用的代码.
Sub Macro1()
'
'
'
'
Dim CountCells
Dim RandCount
Dim LastRow
Dim Counter1
Dim Counter2
Worksheets.Add().Name = "Sheet1"
Worksheets("Employee ID#").Select
Range("a2:A431").Select
Selection.Copy
Worksheets("Sheet1").Select
Selection.PasteSpecial
Worksheets("Sheet1").Select
Range("A1").Select
CountCells = WorksheetFunction.Count(Range("A:A")) 'quantity of random numbers to pick from
If CountCells = 0 Then Exit Sub
On Error Resume Next
Application.DisplayAlerts = False
RandCount = Application.InputBox(Prompt:="How many random numbers do you want?", _
Title:="Random Numbers Selection", Type:=1)
On Error GoTo 0
Application.DisplayAlerts = True
RandCount = Int(RandCount)
If Int(RandCount) …Run Code Online (Sandbox Code Playgroud)