如何在单元格A1中随机输入以下代码“ Jack”或“ John”?当前,结果始终为“ 2”:

Sub RandomNames ()

Dim UserNames(1 To 2) As String

UserNames(1) = "Jack"
UserNames(2) = "John"

Range("A1").Value = Application.WorksheetFunction.RandBetween(LBound(UserNames), UBound(UserNames))

End Sub

最佳答案

尝试在阵列上使用randbetween。

10-05 21:43