Archiv der Kategorie: Officesuite

VBA: Werte in Excel mittels Zufallszahl verändern

Sub RandomizeColumn()
    Dim row As Integer
    Dim originalValue As Variant
    Dim randomFactor As Variant
    Dim column As Integer
    column = 5      'randomize the values of the 5th column

    For row = 2 To 10000      'begin with the 2nd row an end with the 10000th row
        originalValue = Cells(row, column).Value
        randomFactor = (WorksheetFunction.RandBetween(-9, 9) * 0.01) + 1
        Cells(row, column) = randomFactor * originalValue
    Next row
End Sub