Password Generator for Excel
Two ways to generate passwords inside a spreadsheet โ a plain formula for quick, disposable values, and a VBA macro for more control. Read the limitations section before using either for a real account.
RAND() and VBA's Rnd() are both standard pseudo-random generators, not designed to resist a determined attacker. Use these for generating disposable test data or placeholder values only โ for real account passwords, use a proper CSPRNG-based generator like this site's main generator.
Method 1: Formula-Based (No Macros)
This formula builds a 12-character password from a fixed character set using RANDBETWEEN() and MID(). It requires no macros or special permissions โ just paste it into a cell.
=TEXTJOIN("",TRUE,MID("ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789",RANDBETWEEN(1,58),1),MID("ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789",RANDBETWEEN(1,58),1),MID("ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789",RANDBETWEEN(1,58),1),MID("ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789",RANDBETWEEN(1,58),1),MID("ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789",RANDBETWEEN(1,58),1),MID("ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789",RANDBETWEEN(1,58),1),MID("ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789",RANDBETWEEN(1,58),1),MID("ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789",RANDBETWEEN(1,58),1),MID("ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789",RANDBETWEEN(1,58),1),MID("ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789",RANDBETWEEN(1,58),1),MID("ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789",RANDBETWEEN(1,58),1),MID("ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789",RANDBETWEEN(1,58),1))
The character set (ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789) deliberately excludes visually ambiguous characters (0, O, 1, I, l) so the result is easier to read and re-type. Each MID(...,RANDBETWEEN(1,58),1) block picks one random character; repeat the block once per desired character.
Note: Excel recalculates RAND()/RANDBETWEEN() on every sheet edit. To "freeze" a generated password, copy the cell and paste it back as a value (Ctrl+Shift+V โ Values only).
Method 2: VBA Macro
A macro is easier to read and maintain than a long nested formula, and lets you generate many passwords into a column with one click.
Function GeneratePassword(Optional Length As Integer = 12) As String
Dim chars As String
chars = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789!@#$%"
Dim i As Integer
Dim result As String
Randomize
For i = 1 To Length
result = result & Mid(chars, Int(Rnd() * Len(chars)) + 1, 1)
Next i
GeneratePassword = result
End Function
Sub FillPasswordColumn()
Dim i As Integer
For i = 1 To 20
Cells(i, 1).Value = GeneratePassword(16)
Next i
End Sub
Paste this into a new module (Alt+F11 โ Insert โ Module), then run FillPasswordColumn to fill cells A1:A20 with 16-character passwords, or call =GeneratePassword(20) directly as a worksheet formula once the macro is defined.
Limitations You Should Know
- Neither
RAND()nor VBA'sRnd()is cryptographically secure. Both use simple PRNGs designed for spreadsheet calculations and simulations, not to resist prediction by an attacker. - The spreadsheet file itself is a record. If you generate passwords in a workbook and save it, that workbook now contains plaintext credentials โ treat the file accordingly, and don't email it or store it in shared, unencrypted locations.
- Formulas recalculate. If you need a password to stay fixed, convert the formula result to a static value before using it anywhere.
Need a password for a real account?
Use a cryptographically secure generator instead of a spreadsheet formula.
Use the Password Generator โFrequently Asked Questions
No. RAND() and RANDBETWEEN() use a standard pseudo-random algorithm suitable for spreadsheet work, not for values that must resist a determined attacker. Use it for disposable test data, not real credentials.
Not through its built-in Rnd() function, which is also a simple non-cryptographic PRNG. Reaching a cryptographic source from VBA requires calling the Windows CryptoAPI directly via Declare statements โ considerably more work than the formula shown here.
A dedicated cryptographically secure generator, such as this site's browser-based generator, which uses crypto.getRandomValues(). Reserve the Excel methods above for disposable or low-stakes values.