insert random letters into selection - an example procedure

  • Thread starter aztecbrainsurgeon
  • Start date
A

aztecbrainsurgeon

no question here, just an example procedure for the archive.

Prompts user for the number of random letters to be inserted into each
cell
in the active selection. The procedure seems to be limited to up to 39
random
letters per cell.

Sub RandomLETTERSGenerator()

'Prompts for the number of Random letters for each cell in selection
'Seems to be limited to up to 39 random letters per cell
On Error Resume Next
Dim LetterNum%
Dim RanBaseLetter, RanAddLetter, RanAllLetters As String
RanBaseLetter = "CHAR(TRUNC(RAND()*26+65))"
RanAddLetter = "&CHAR(TRUNC(RAND()*26+65))"

LetterNum = Application.InputBox(prompt:="How many random letters
do you want in each cell in selection?", Title:="Insert Random
Letter(s)", _
Default:=1, Type:=1) 'type 1 is
number

If LetterNum = False Then Exit Sub

If LetterNum = 1 Then
Selection.FormulaR1C1 = "=" & RanBaseLetter
End If

If LetterNum > 1 Then

For i = 1 To LetterNum - 1
RanAllLetters = RanAddLetter & RanAllLetters
Next i

Selection.FormulaR1C1 = "=" & RanBaseLetter & RanAllLetters

End If

'Paste value the formulas
Selection.Value = Selection.Value

End Sub

return random letters
insert random letters
generate random letters
random letter generator
prompt for random letter(s) insertion
 

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