防止选择空单元格和特定值

时间:2017-08-29 14:32:00

标签: excel-vba vba excel

我尝试创建一个随机选择列表中特定行数的代码。我希望阻止选择空行和某些特定值的问题,例如" 54555"。也许有人可以帮助我?这是我的代码

Sub Button1_Click()
Dim d As Object, r As Range, vKeys, x&

'get a set of 3 unique numbers
Set d = CreateObject("Scripting.Dictionary")
While d.Count < 3
'Define the min,max of your numbers
x = RndBetween(6, 11)
If Not d.Exists(x) Then d.Add x, Empty
Wend

'Create a multiarea range
vKeys = d.keys
Set r = Rows(vKeys(0))
For x = 1 To UBound(vKeys)
Set r = Union(r, Rows(vKeys(x)))
Next
'Select it
r.Select
Selection.Copy
Range("A1").Select
Worksheets("Ausinës").Paste
r.Delete

End Sub

Function RndBetween(low&, high&) As Long
RndBetween = CLng(Rnd * (high - low)) + low
End Function

0 个答案:

没有答案