Hello everybody,
I have to generate a string of letters of this kind:
M + 7 letters
for example :
MAZERTYU
MPOISURE
etc
What kind of code could I use ?
Thanks
Printable View
Hello everybody,
I have to generate a string of letters of this kind:
M + 7 letters
for example :
MAZERTYU
MPOISURE
etc
What kind of code could I use ?
Thanks
[vba]
Dim num As Long
Dim tmp As String
Dim i As Long
tmp = "M"
For i = 1 To 7
tmp = tmp & Chr(64 + Int((Rnd() * 26) + 1))
Next i
Debug.Print tmp
[/vba]
Great, it works perfectly, my boss will be happy!
Thank you so much XLD
That's okay. But can I ask what possible use you have for this code, I am intrigued?Quote:
Originally Posted by Dabo
Sure,
I have a list of Ids for customers
"M0000001" = customer 1
"M0000002" = customer 2
etc
I need to let the user add new customers.
When he doesn't know the Id of the customer, I need to generate a new one with letters instead of figures, to be able to recognize them.
What happens if it generates a string you have already used?
I put a test to avoid that and generate a new string until it's ok
(even if it is highly unlikely)