ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   insert random letters into selection - an example procedure (https://www.excelbanter.com/excel-programming/357890-insert-random-letters-into-selection-example-procedure.html)

[email protected]

insert random letters into selection - an example procedure
 
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



All times are GMT +1. The time now is 10:26 AM.

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