我正在用 VBA Excel 撰寫 War the Card Game。我想從 A 列和 B 列中獲取一個隨機值。我研究了它,似乎可以生成一個亂數。
Dim ws As Sheet1
P1LR = Cells(Rows.Count, 1).End(xlUp).Row
P2LR = Cells(Rows.Count, 2).End(xlUp).Row
P1Cards = WorksheetFunction.RandBetween(A1, P1LR)
P2Cards = WorksheetFunction.RandBetween(A1, P2LR)
但是,它給了我行的值,而不是單元格中實際的值。我將如何使用此函式獲得該值?
uj5u.com熱心網友回復:
你可以通過變數來尋址單元格,試試這樣:
Dim ws As Sheet1
P1LR = Cells(Rows.Count, 1).End(xlUp).Row
P2LR = Cells(Rows.Count, 2).End(xlUp).Row
P1Cards = WorksheetFunction.RandBetween(A1, P1LR),
P2Cards = WorksheetFunction.RandBetween(A1, P2LR)
Cells(P1Cards, 1).Select
Cells(P2Cards, 2).Select
或者
Cells(WorksheetFunction.RandBetween(A1, P1LR), 1).Select
Cells(WorksheetFunction.RandBetween(A1, P2LR), 2).Select
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/358516.html
上一篇:查找相關字串在串列中的位置
下一篇:范圍聯合方法有問題
