Hello,
My script gives a randomly generated number between a range of numbers the user specifys. Take 2100 and 2199. The script will generate a random number between those numbers. But before the script generates the number - I want to compare it too a list on another sheet to see if the number already was generated previously.
I have the script working, as in, it generates the number, but I get a 'method 'range' of object_worksheet failed' error. Then VBE highlights the 'myresult = isNumber' line.
Any ideas why that could be?
My script gives a randomly generated number between a range of numbers the user specifys. Take 2100 and 2199. The script will generate a random number between those numbers. But before the script generates the number - I want to compare it too a list on another sheet to see if the number already was generated previously.
I have the script working, as in, it generates the number, but I get a 'method 'range' of object_worksheet failed' error. Then VBE highlights the 'myresult = isNumber' line.
Any ideas why that could be?
Code:
Private Sub CommandButton1_Click()
Dim i As Long
Dim myResult As Boolean
Dim myValue As Integer
Low = Application.InputBox("Minimum Number", Type:=1)
High = Application.InputBox("Maximum Number ", Type:=1)
Selection.Clear
MsgBox "Sorry this number exists. Excel will now generate a new number!"
For Each cell In Selection.Cells
If WorksheetFunction.CountA("A:A") = (High - Low + 1) Then Exit For
Do
rndNumber = Int((High - Low + 1) * Rnd() + Low)
Loop Until Selection.Cells.Find(rndNumber, LookIn:=xlValues, lookat:=xlWhole) Is Nothing
cell.Value = rndNumber
Next
myResult = IsNumeric(Application.Match(myValue, Range("Sheet4!A1:A1631"), 0))
ActiveCell.Offset(1).Activate
End Sub