RAND против RANDBETWEEN
Чтобы включить RANDBETWEEN
, в Excel вам нужно перейти в Инструменты> Надстройки и проверить пакет инструментов анализа.
Sub Bestand()
Const cWs1 As String = "Interface" ' First Worksheet
Const cWs2 As String = "Deelnemersbestand" ' Second Worksheet
Const cRngName As String = "aantalDeelnemers" ' Cell Range in First Worksheet
Const cColumn As Variant = "B" ' Column Letter/Number
Const cFirstRow As Integer = 2 ' First Row of Data
Const cFormula As String = "=RAND()" '"=RANDBETWEEN(21,50)"
Dim i As Integer
i = Worksheets(cWs1).Range(cRngName).Value
With Worksheets(cWs2)
.Range(.Cells(cFirstRow, cColumn), .Cells(i, cColumn)).Formula = cFormula
.Range(.Cells(i + 1, cColumn), .Cells(.Rows.Count, cColumn)).ClearContents
End With
End Sub