我正在尝试从另一个工作表中选择一个随机单元格。如果我在代码所在的当前工作表上选择一个随机单元格,则以下代码有效。如何从另一个工作表中选择一个随机单元格?
Dim e
Static myList As Object
If myList Is Nothing Then
Set myList = CreateObject("System.Collections.SortedList")
End If
If myList.Count = 0 Then
Randomize
For Each e In Range("D3:D32", Range("D" & Rows.Count).End(xlUp)).Value
myList.Item(Rnd) = e
Next
End If
MsgBox myList.GetByIndex(0)
myList.RemoveAt 0
这是我试图从另一张纸中选择的内容。
Dim e
Static myList As Object
If myList Is Nothing Then
Set myList = CreateObject("System.Collections.SortedList")
End If
If myList.Count = 0 Then
Randomize
For Each e In Workbooks("Test").Sheets("Sheet1").Range("D3:D32", Range("D" & Rows.Count).End(xlUp)).Value
myList.Item(Rnd) = e
Next
End If
MsgBox myList.GetByIndex(0)
myList.RemoveAt 0
关于我做错了什么的建议?