Password generator in a cell

mrkris1982

Active Member
Joined
Apr 16, 2009
Messages
407
Whats the best way to accomplish this in a cell in 2013?

The password constraints are:
Must be exactly 8 characters
at least 1 uppercase letter
at least 1 lowercase letter
at least 1 number
no special characters

I'm open to anything whether it be VBA Code, a button or programming an F* key to invoke the password to change when clicked or pressed. Thanks ahead of time for any help offered.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Here's some code I just came up with, might be a better way to do it, but this seems to do the trick:

Code:
Sub gen()

Randomize

Dim i As Long
Dim aLetters(1 To 62) As String 'array to store all possible values
Dim lRandom As Long
Dim sPW As String 'generated password

Dim bLowCheck As Boolean
Dim bUpCheck As Boolean
Dim bNumCheck As Boolean

'load numbers to array
For i = 1 To 10
    aLetters(i) = Chr(i + 47)
Next i

'load UCase and LCase text to array
For i = 1 To 26
    aLetters(i + 10) = Chr(i + 64) 'upper
    aLetters(i + 36) = Chr(i + 96) 'lower
Next i

Do Until bLowCheck = True And bUpCheck = True And bNumCheck = True
    bLowCheck = False
    bUpCheck = False
    bNumCheck = False
    sPW = ""
    
    For i = 1 To 8
        lRandom = CLng(62 - 1 + 1) * Rnd + 1
        If lRandom = 0 Then lRandom = 1 'think sometimes this is zero, which causes an error
        sPW = sPW & aLetters(lRandom)
        Select Case lRandom
            Case 1 To 10
                bNumCheck = True
            Case 11 To 36
                bUpCheck = True
            Case 37 To 62
                bLowCheck = True
        End Select
    Next i
Loop

MsgBox sPW

End Sub
 
Upvote 0
ChrisM....what are the steps that I need to take before adding this VBA code? Is this a command button, macro, F key? Look forward to trying it-thanks!
 
Upvote 0
You can launch it several different ways, certainly a command button would work. Do you know how to do that?

For a Form Command button, copy my code into a module in VBE. Then create a button, choose assign macro and you should see my sub name "gen".
 
Upvote 0
This works and it pops up a window with the random password in it...however, i would need the ability to copy the password from whereever it is displayed. I don't seem to have the ability in the window. Is there a way to make this happen?
 
Upvote 0
I put it in the pop up window because you didn't specify where you want the password output to. Where do you want the password? In a cell? On the clipboard?
 
Upvote 0
I honestly didnt even think about the options for where the password would be displayed--my aplogies for that. Im not sure what the clipboard is but willing to try it. If all else fails, we can just go wtih the cell option and I can adjust the code to go into a specific cell in my worksheet...but I think the button or whatever would go in B33 and the output can go in C33
 
Upvote 0

Forum statistics

Threads
1,215,453
Messages
6,124,925
Members
449,195
Latest member
Stevenciu

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