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.

Neither method below is cryptographically secure. Excel's 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.

excel formula
=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.

vba
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

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.

Related