Division 2 numbers

  • Thread starter Thread starter gregor
  • Start date Start date
G

gregor

Hello I want generate at random numbers in 2 columns that results division
was be only integer example:
6/2=3 or 4/2=2 or 9/3=3

i will be do that in visual basic

thx for help
gregor
 
One way:

Option Explicit
Sub testme()

Dim myRng As Range
Dim wks As Worksheet

Dim MaxNumber As Long
Dim MinNumber As Long
Dim maxResult As Long
Dim minResult As Long

MaxNumber = 25
MinNumber = 3

maxResult = 10
minResult = 2

Set wks = ActiveSheet
With wks
Set myRng = .Range("b1:b20")
With myRng
.Formula = "=int(rand()*" & MaxNumber - MinNumber + 1 _
& "+" & MinNumber & ")"
.Offset(0, -1).FormulaR1C1 = "=rc[1]*INT(RAND()*" _
& maxResult - minResult + 1 & "+" & minResult & ")"
With .Offset(0, -1).Resize(, 2)
.Value = .Value
End With
With .Offset(0, 2)
.FormulaR1C1 = "=rc[-3]/rc[-2]"
.EntireColumn.Hidden = True
End With
End With
End With

End Sub

It actually puts random numbers between minnumber and maxnumber (3 & 25) in a
column. Then it multiplies that number by a random number between minresult and
maxresult (2 & 10). And puts that number into the column to the left.

And to make your life easier for checking, it puts the quotient in a hidden
column. I used columns B, A and D for my example.
 
Back
Top