Hi,
I am now completely stuck.
I have the following VBA script to generate a string of random characters in a specific cell.
I would like this to work for a number of cell at the same time.
Is this possible? how can i change my existing code so that instead of D15 a range of selected cells (for example C10 thru to C15 and E5) can be generated at the same time however making all the codes different (and if possible unique)
would really be appreciated.
Sub PasswordGenerator()
Dim Password As String
Dim PasswordLength As Byte
Dim LC As Byte 'Loop Counter
Dim strRndmChr As String
Dim LAC As Byte 'Lowest Ascii Character
Dim HAC As Byte 'Highest Ascii Character
Dim UseSymbolics As Boolean
Dim HasSymbolics As Boolean
Dim RandomNumber As Byte
'Set parameters.
PasswordLength = 6
'Visit www.lookuptables.com for the ascii table.
LAC = Asc("0")
HAC = Asc("z")
UseSymbolics = False
Randomize
For LC = 1 To PasswordLength
'To produce random integers in a given range, use this formula:
'Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
Do
RandomNumber = Int((HAC - LAC + 1) * Rnd + LAC)
strRndmChr = Chr(RandomNumber)
HasSymbolics = CheckSymbolics(RandomNumber)
Loop Until UseSymbolics = True Or HasSymbolics = False
Password = Password & strRndmChr
Next LC
Range("D15").Value = Password
'ActiveCell = Password
End Sub
Private Function CheckSymbolics(RandomNumber As Byte)
If (RandomNumber >= 33 And RandomNumber <= 47) Or _
(RandomNumber >= 58 And RandomNumber <= 64) Or _
(RandomNumber >= 91 And RandomNumber <= 96) Or _
(RandomNumber >= 123 And RandomNumber <= 126) Then _
CheckSymbolics = True Else: CheckSymbolics = False
End Function
Bookmarks