2017-04-20 9 views
-1

行の値に応じてランダムな値を生成します。
私は試しました:=if(row:row>50;Rand()) これは私にRand()値を1つの列に与えます。
最後に、私が望む方法ではなく、私が望む値の量を生成します。行の値に応じて列を作成するExcelシミュレーション

例:

3 rd rd rd 
2 rd rd 
1 rd 

私はマクロを使用したい4つの000シミュレーション

+0

編集が表示されませんでした –

答えて

0

を持っています。

は、あなたの値は、セルA1を選択し、セルB1に起動し、以下のマクロを実行し、あなたは別々のセルにあなたの乱数を取得します言ってやるがいい。

enter image description here

Sub CreateRandomNumbers() 
Dim i As Integer: Dim q As Integer 
Dim startingRow As Integer: Dim startingColumn As Integer 
Do While ActiveCell.Offset(0, -1).Value <> "" 
    'Store number of random numbers required in "q" 
    q = ActiveCell.Offset(0, -1).Value 
    'Store starting row and column 
     startingRow = ActiveCell.Row 
     startingColumn = ActiveCell.Column 
    'Exit sub if q = 0 
    If q = 0 Then 
     MsgBox "No random number required." 
     Exit Sub 
    End If 
    'Calculate random numbers 
    For i = 1 To q: ActiveCell.Value = Rnd(): ActiveCell.Offset(0, 1).Select: Next i 
    'Go back to starting cell 
    Cells(startingRow, startingColumn).Select 
    'Go to next row in the same columns 
    ActiveCell.Offset(1, 0).Select 
Loop 
End Sub 

は次のようになります

私はそれが助けてくれることを願っています。

関連する問題