天兒真好,Excel VBA中產生一個隨機數,以便根據有多少
我有按照排序順序獲得隨機數的棘手的問題我需要多少由內VBA無論是VBA代碼或公式。這需要在1到10之間隨機生成。
它在啓動時看起來像這樣。
,這裏是我腦子裏想的效果,即它是根據有多少的例子失敗排序號。
這是一個試圖通過VBA我在哪裏電池J7包含隨機的我需要多少,但數量不大排序。我願意在這裏提供建議/反饋。非常感謝。
Public Const BeCoolMachineCounter As String = "J7"
Public Const BeCoolMachineRange As String = "Q03:Q12"
'Generate the random data according to how many needed.
Call CreateNumbers(Range(BeCoolMachineRange), Range(BeCoolMachineCounter).Value)
Private Sub CreateNumbers(Which As Range, HowMany As Integer)
' Declaration of variables
Dim c As Range
Dim iCheck As Long
iCheck = 1
' Generate random failures based on the number of required for each supplier
For Each c In Which
If iCheck <= HowMany Then
c.Value = Random1to2192
iCheck = iCheck + 1
End If
Next c
End Sub
如果電子表格佈局是靜態的,我想嘗試'SMALL'工作表函數。 –
嗨朱裏,我不認爲小工作表函數是必需的,因爲這意味着一個數字。感謝您提出建議。 –
'=小($ B $ 3:$ B $ 12),ROW() - 2'從C3複製到單元格'C3:C12'您的示例將排序所有輸出數據。 –