Below is a function that is supposed to return a random value between 1 and 10
that is not already in column A
. It works fine in terms of finding the random value and exiting the loop but in excel when called using =Ang()
the function returns #Value!
as below.
Function Ang()
i = 0
Do
i = Application.WorksheetFunction.RandBetween(1, 10)
Ang = i
MsgBox Ang
Loop While Application.WorksheetFunction.IfNa(Application.WorksheetFunction.Match(i, Worksheets("Sheet2").Range("A:A"), 0), 0)
End Function