【问题标题】:Excel simulation creating column according to value in the rowExcel模拟根据行中的值创建列
【发布时间】:2017-04-20 14:23:20
【问题描述】:

我想根据行中的值生成随机值。
我试过了:=if( row:row>50;Rand ()) 但这仅在一列上给了我Rand() 值。
最后,我生成了我想要的值,但不是以我想要的方式。

例子:

3 rd rd rd
2 rd rd
1 rd

我有 4000 次模拟

【问题讨论】:

  • 糟糕,我没有看到编辑谢谢

标签: excel simulation


【解决方案1】:

我会使用宏。

假设您的值从单元格 A1 开始,选择单元格 B1 并运行下面的宏,您将在单独的单元格中获得随机数:

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

看起来像这样:

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-24
    • 2022-01-01
    • 1970-01-01
    • 2021-02-28
    相关资源
    最近更新 更多