(Solved) – Why the below function is not returning any value and it is always returns empty

(solved)-–-why-the-below-function-is-not-returning-any-value-and-it-is-always-returns-empty

Below is my program to get the random number from the function called ‘RandomNum’

Sub Test()

Dim RandomNo As Variant

RandomNo = RandomNum(RandomNo)
Range("B6").Value = RandomNo

End Sub

Below is the code for the function called ‘RandomNum’ and it is used to create a 8-digit random alpha numeric text. It always returns an empty value to the main function

Public Function RandomNum(RandomNo As Variant) As Variant

alphaNumericText = UCase("abcdefghijklmnopqrstuvwxyz0123456789")
alphaText = UCase("abcdefghijklmnopqrstuvwxyz")

RandomNo = ""
Randomize
For i = 1 To 8
    RandomNo = RandomNo & Mid$(alphaNumericText, Int(Rnd() * Len(alphaNumericText)   1), 1)
Next

End Function

Leave a Reply

Your email address will not be published. Required fields are marked *