ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Return a random letter (https://www.excelbanter.com/excel-programming/318253-re-return-random-letter.html)

quartz[_2_]

Return a random letter
 
Thanks Tom. You've done it again!
I was not familiar with the "Asc" conversion.

"Tom Ogilvy" wrote:

So you could add another function that uses your existing function:

Public Function RandomLetter()
Dim argLow As Long, argHigh As Long
argLow = Asc("A")
argHigh = Asc("Z")
RandomLetter = Chr(RandomNumbers(argLow, argHigh))
End Function


Public Function RandomNumbers(argLow As Long, argHigh As Long) As Long

'RETURN A RANDOM NUMBER BETWEEN 'argLow' AND 'argHigh'
Randomize
RandomNumbers = CLng((argHigh - argLow) * Rnd + argLow)

End Function


from the immediate window:

? RandomLetter()
T


--
Regards,
Tom Ogilvy

"quartz" wrote in message
...
I have the following function which works great for returning a random
number in a range from a specified low to a specified high:

Public Function RandomNumbers(argLow As Long, argHigh As Long) As Long

'RETURN A RANDOM NUMBER BETWEEN 'argLow' AND 'argHigh'
Randomize
RandomNumbers = CLng((argHigh - argLow) * Rnd + argLow)

End Function

Now I need a similar function that would return a random letter between A
and Z. Can anyone suggest a more efficient method than just assigning all

the
letters of the alphabet to numbers between 1 and 26 to return a random

letter?

Thanks in advance.






All times are GMT +1. The time now is 05:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com