Skip to main content

How to generate random character strings in a range in Excel?

Sometimes you may need to generate random strings in cells, such as different passwords. This article tries to show you some tricks to generate different random strings in Excel.

Generate random character strings with formulas
Generate random character strings with VBA code
Easily generate random character strings with Kutools for Excel


Generate random character strings with formulas

The following formulas can help you generate random numbers, letters and alphanumeric values in a range in Excel.

1. To create a random 5-digit number between 10000 and 99999, use this formula: =RANDBETWEEN(10000,99999), and press Enter key, a 5-digit number will be display in a cell, then select the cell and drag the fill handle across to the range that you want to contain this formula, a range of 5-digit numbers have been generated, see screenshots:

doc-generate-strings1 -2 doc-generate-strings2

Note: you can change the arguments to get your need.

2. To create a random letter, use the this formula: =CHAR(RANDBETWEEN(65,90)). This formula can generate a random letter from a to z, if you need to create four random letters, you need to use & character to add the letters. Such as =CHAR(RANDBETWEEN(65,90))& CHAR(RANDBETWEEN(65,90)) & CHAR(RANDBETWEEN(65,90)) & CHAR(RANDBETWEEN(65,90)). Then you will get a four random letters, and then drag the fill handle over to the range that you want to contain this formula. See screenshot:

doc-generate-strings3

Notes:

(1.)The formula is valid in Excel 2007, 2010, and 2013, but not Excel 2003. In Excel 2003, please use the formula =CHAR(INT(RAND()* 25 + 65)) & CHAR(INT(RAND()* 25 + 65)) & CHAR(INT(RAND()* 25 + 65)) & CHAR(INT(RAND()* 25 + 65))

(2.) In formula 65 is A and 90 is Z.

(3.) You can use the character & to add the number of letters you need.

3. To create a random alphanumeric string that has two letters and two numbers, use this formula: =CHAR(RANDBETWEEN(65,90))&CHAR(RANDBETWEEN(65,90))&RANDBETWEEN(10,99) And you will get the following strings in a range which contain two letters and two numbers:

doc-generate-strings4

Note: you can change the arguments to get the digit number as you need, and use & to add the number of letters.

Easily generate random character strings in selected range:

It is easy to generate random character strings with specific characters and text length with the Insert Random Data utility of Kutools for Excel.
Download Kutools for Excel Now! (30-day free trail)


Generate random character strings with VBA code

If you feel above formulas are difficult and troublesome, the following VBA code can help you much easier. Please do as this:

1. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and paste the following macro in the Module window.

Public Function RandomizeF(Num1 As Integer, Num2 As Integer)
'Update 20131107
Dim Rand As String
Application.Volatile
getLen = Int((Num2 + 1 - Num1) * Rnd + Num1)
Do
    i = i + 1
    Randomize
    Rand = Rand & Chr(Int((85) * Rnd + 38))
Loop Until i = getLen
RandomizeF = Rand
End Function

3. Then save and close the code, in a cell, enter this function =RandomizeF(x,y) to insert a random character string with a minimum length of x characters, and a maximum length of y characters.

4. In this example, I will use function =RandomizeF(5,10) to generate a character string which between 5 and 10 characters. Then press Enter key, select the cell and drag the fill handle to the range you want to contain this function. And random of alphanumeric and specific character strings which between 5 and 10 characters have been created. See screenshot:

doc-generate-strings5


Generate random character strings with Kutools for Excel

Is there a way to generate random strings with letters, numbers, and special characters, or more? Kutools for Excel's Insert Random Data is an excellent random number (and text string) generator, which can generate random numbers, random text string, or random numbers & text& symbols with all kinds of characters, including letters, numbers, special characters, space, and even custom strings.

Before applying Kutools for Excel, please download and install it firstly.

1. Select a range in which you will generate random strings, and then click Kutools > Insert > Insert Random Data. See screenshot:

3. In the Insert Random Data dialog box, click String tab, and choose the type of characters as you need, then specify the length of the string in the String length box, and finally click the OK button. See screenshot:

Then the selected range has been filled with random character strings.

Tip: if you want to generate or insert a specified formatting data strings (such as ????@.??.com) in a range, you can also use this utility. Do as this:

1. Select a range and specify the characters and check By mask. Then input the specified data strings you need. See screenshot:

Note: Using ? to indicate a digit of random character in the final specified formatting strings.

2. Then click OK or Apply. The specified formatting data strings have been generated randomly as follows. See screenshot:

Kutools for Excel's Insert Random Data can help you easily process the following operations in a range cells.

  • Generate or insert random numbers in a range
  • Generate or insert random date in a range
  • Generate or insert a custom list in a range

  If you want to have a free trial (30-day) of this utility, please click to download it, and then go to apply the operation according above steps.


Demo: Generate random character strings in a range


Related Article:

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions…
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...

Description


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!

Comments (29)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
I found this useful as a starting point--I hadn't touched VBA in several years, so it was way easier to use the sample code here as a basis than start from scratch. Skelly1008, have you thought about something like this? Do Randomize charVal = (Int(85 * Rnd) + 48) If charVal > &H30 And charVal < &H7A Then If Not (charVal > &H5A And charVal < &H61) Then If Not (charVal > &H39 And charVal < &H41) Then newChar = Chr(charVal) Rand = Rand & newChar End If i = i + 1 End If End If Loop Until i = getLen That generates strings that contain only a-z, A-Z, and 0-9.
This comment was minimized by the moderator on the site
I'm looking for a code that can generate any number 0 to 9 and or any letter A to Z. But I need 25 characters in the that final out put.
This comment was minimized by the moderator on the site
Found way: 1st: For each char: =RANDBETWEEN(0;1) to randomly select a number or a letter (result in A2 to A9, for example) 2nd: =IF(An=0;RANDBETWEEN(0;9);CHAR(RAND()*26+97)) - in B2 to B9 -> to generate a number or a letter depending on result in A column 3rd: in the cell you want the generated password: =B2&B3&B4&B5&B6&B7&B8&B9
This comment was minimized by the moderator on the site
I live the formula but once I enter something in another field the numbers in the random fields change. I only want it to randomly generate one time. Not every time I enter data in other fields on the worksheet. Is that a separate function? Thanks!
This comment was minimized by the moderator on the site
Hi I want one help from you. I have to replace one last three values in this text for example: LoadTesting . I want to change only last three word of it
This comment was minimized by the moderator on the site
[quote]Hi I want one help from you. I have to replace one last three values in this text for example: LoadTesting . I want to change only last three word of itBy rOHIT[/quote] Assuming it is in cell A1:

=MID(A1,1,LEN(A1)-3)&"CAT"
This comment was minimized by the moderator on the site
Hi, On generating the random number in excel,can we insert the value to a form?any query plz share
This comment was minimized by the moderator on the site
This is several times better than I dared hope for!! I completely disregarded the idea of generating several values in a single cell. Guaranteed I'll be using this info every chance I get! 11/10.
This comment was minimized by the moderator on the site
Hi i would like to make the same in a MS WORD tab. is it possible ?
This comment was minimized by the moderator on the site
The VBA isn't working as a true random number. I'm using (10,12) as the criteria and if I run it down a couple thousand rows and do a countif formula in the adjacent column I find many duplicate passwords.
This comment was minimized by the moderator on the site
Very helpful, thank you. Using the VBA code, is it possible to only show letters and numbers and not other symbols?
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
Rate this post:
0   Characters
Suggested Locations