如何从动态数组中读取数据?
ReDim idx(1 To nItemsToPick)
ReDim varRandomItems(1 To nItemsToPick)
For i = 1 To nItemsToPick
Do
booIndexIsUnique = True
idx(i) = Int(nItemsTotal * Rnd + 1)
For j = 1 To i - 1
If idx(i) = idx(j) Then
booIndexIsUnique = False
Exit For
End If
Next j
If booIndexIsUnique = True Then
Exit Do
End If
Loop
varRandomItems(i) = rngList.Cells(idx(i), 1)
Next i
谢谢!
答案 0 :(得分:1)
不知何故,你必须让用户输入一个起始单元格,以及他们是否想要水平或垂直数据。
然后,如果用户输入“A1”,并且有10个元素且方向是水平的,则需要将其转换为字符串 - > “A1:A10”
Range("A1:J10") = varRandomItems
或
Range("A1:A10") = Application.Transpose(varRandomItems)
(道歉,我忘记了如何将字符串放在一起)