Dear folks,
hope that all is well.
I am having some troubles with a vba code.
1. Generating random variables within an interval
2. Creating a loop where if the random number generated is within an earlier interval it would generate a new random number
So as for now I only get "1" on rows 10-19. And then I would like to create a loop that checks if the value generated is already in an array above the row of which the generated number is. If it is in this array then the loop would generate another random number.
Please see below code for what I have been attempting;
As always, many thanks in advance!
Kind regards
Dailan
hope that all is well.
I am having some troubles with a vba code.
1. Generating random variables within an interval
2. Creating a loop where if the random number generated is within an earlier interval it would generate a new random number
So as for now I only get "1" on rows 10-19. And then I would like to create a loop that checks if the value generated is already in an array above the row of which the generated number is. If it is in this array then the loop would generate another random number.
Please see below code for what I have been attempting;
VBA Code:
Sub RNG_Click()
r
Dim ws1, ws2 As Worksheet
Dim i, Nr_rows, stokastiskt1, RNG As Integer
Sheets("Stickprov").Activate
Set ws1 = Worksheets("Stickprov")
Set ws2 = Worksheets("Beviljade ansökningar")
Nr_rows = ws2.Range("A2").End(xlDown).Row
RNG = Int((Nr_rows * rnd) + 1)
stokastiskt1 = ws1.Range("A3:A9").value
For i = 10 To 19
Cells(i, 1).value = RNG
' If Cells(i, 1) = stokastiskt1 Then
' Cells(i, 1).value = RNG
' End If
Next i
MsgBox "Sample is provided"
End Sub
As always, many thanks in advance!
Kind regards
Dailan