Random Password Generator

farhad

New Member
Joined
May 18, 2009
Messages
41
Good Day

I have the following VB code that generates a 10 character alphanumeric password. This code works perfectly fine.

However I would like to change the code to include special characters in the password.

The characters are limited to !@#$&*

Code:
Sub TenCharPassword()
    Dim i As Integer, c As Integer, n As Integer, pw As String
    For i = 1 To 100
        pw = ""
        For n = 1 To 10
            c = Evaluate("=RandBetween(65,100)")
            If c > 90 Then c = c
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hi shg

This the code I have that is generating error ?NAME

Code:
Sub farhad()
  With Range("A1:A100")
    .Formula = "=TenCharPassword()"
    .Value = .Value
  End With
End Sub
  Function TenCharPassword(numChars As Integer)
  Const sSym As String = "[EMAIL="ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$*0123456789"]ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$*0123456789[/EMAIL]"
  Dim i As Long
  
  For i = 1 To 10
   TenCharPassword = TenCharPassword & Mid(sSym, [=RandBetween(1,32)], 1)
    Next i
End Function
 
Upvote 0
This the code I have that is generating error ?NAME

(numChars As Integer) - not required

Code:
Sub farhad()
  With Range("A1:A100")
    .Formula = "=TenCharPassword()"
    .Value = .Value
  End With
End Sub

Function TenCharPassword[COLOR=#ff0000]()[/COLOR]
  Const sSym As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$*0123456789"
  Dim i As Long
   For i = 1 To 10
     TenCharPassword = TenCharPassword & Mid(sSym, [=RandBetween(1,32)], 1)
   Next i
End Function

The function should be placed in a standard module if used like this
 
Last edited:
Upvote 0
Dear Yongle

my apologies for late reply. Your code has worked. Once again thanks for all your assistance.
Greatly appreciated.
Once again thanks
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,301
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top