I have following code and it does half the trick
when cell N2 = "divide" the randum number shuld only be dividable with cell value J2
When cell N2 is not "divide" the code should stay as it is
when cell N2 = "divide" the randum number shuld only be dividable with cell value J2
When cell N2 is not "divide" the code should stay as it is
Code:
Public Sub generateRandNum1()
'Define your variabiles
Dim lgetal As String
Dim hgetal As String
lgetal = Worksheets("Blad 2").Range("f2").Value
hgetal = Worksheets("Blad 2").Range("h2").Value
lowerbound = lgetal
upperbound = hgetal
Set randomrange = Range("B9:B13")
randomrange.Clear
For Each rng1 In randomrange
counter = counter + 1
Next
If counter > upperbound - lowerbound + 1 Then
MsgBox ("Number of cells > number of unique random numbers")
Exit Sub
End If
For Each Rng In randomrange
randnum = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
Do While Application.WorksheetFunction.CountIf(randomrange, randnum) >= 1
randnum = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
Loop
Rng.Value = randnum
Next
End Sub