|
楼主 |
发表于 2024-5-19 12:55
|
显示全部楼层
感谢老师及时的回复,我想多了解一下,如果我还有c列需要显示呢,
我大概知道dic(k)显示的是dic(arr(x, 1)) = arr(x, 2)这个的赋值
K应该是dic.keys的值,那么C列的值该如何赋值?
Sub 随机()
Dim arr, brr
Dim dic
Set dic = CreateObject("scripting.dictionary")
h = Sheets("陌生词").Range("a65536").End(xlUp).Row
arr = Sheets("陌生词").Range("a2:c" & h)
For x = 1 To UBound(arr)
dic(arr(x, 1)) = arr(x, 2)
Next
On Error Resume Next
h1 = Sheets("单词").Range("a65536").End(xlUp).Row
brr = Sheets("单词").Range("a2:a" & h1)
For i = 2 To UBound(brr)
If dic.exists(brr(i, 1)) Then
dic.Remove (brr(i, 1))
End If
Next
If dic.Count > 0 Then
n = Int((dic.Count - 1 + 1) * Rnd + 1)
k = Application.Index(dic.keys, n)
Sheets("单词").Cells(h1 + 1, 1) = k
Sheets("单词").Cells(h1 + 1, 2) = dic(k)
Sheets("单词").Cells(h1 + 1, 3) = ?
End If
End Sub
|
|