insert combination of random letters and numbers - an example

  • Thread starter aztecbrainsurgeon
  • Start date
A

aztecbrainsurgeon

No question here, just a procedure example for the archive.

Insert a specified length of a random letter and number combination
into each cell in the selection

Sub RandomLetterNumberCombinations()

'Prompts for the length of a Random letter and number
'combination that is inserted into each cell in selection


Dim RandomLetOrNum, RanNumOrLetDecider As Integer
Dim c As Range
Dim FinalResult As String
Dim Length%
On Error Resume Next
Length = Application.InputBox(prompt:="What length would you like
the random letter/number

combination for each cell in selection?", Title:="Insert Random Letter
Number Combinations", _
Default:=1, Type:=1) 'type 1 is
number

If Length = False Then Exit Sub

For Each c In Selection
For i = 1 To Length

RanNumOrLetDecider = Int(Rnd * 2) 'decide whether number
or character
If RanNumOrLetDecider = 1 Then
RandomLetOrNum = Int(9 * Rnd())
End If
If RanNumOrLetDecider = 0 Then
RandomLetOrNum = Chr(Rnd() * 26 + 65)
End If
FinalResult = RandomLetOrNum & FinalResult
Next i

c.Value = FinalResult
''Reset the result to nothing for the next cell's calculation
FinalResult = ""
Next c
End Sub

search criteria:
random letter and number generator
random combination of letters and numbers
random numbers and letters in combination
combination random letters and numbers
insert random characters
return random combinations
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top