別のワークシートからランダムなセルを選択しようとしています。コードがある現在のシートでランダムなセルを選択すると、次のコードが機能します。別のシートからランダムなセルを選択するにはどうすればよいですか?
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
私が間違っていることについての提案はありますか?