Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Generate a Random 6 Digit Number in Excel: Easy Guide

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To generate a random 6-digit number in Excel, use the formula =RANDBETWEEN(100000, 999999). This function tells Excel to pick a whole number between the lowest possible 6-digit value (100,000) and the highest possible 6-digit value (999,999), ensuring the result always has exactly six digits. This is useful for creating unique IDs, raffle tickets, verification codes, or sample data for testing spreadsheets.

What You'll Need

  • A computer with Microsoft Excel installed (works on Office 365, Excel 2021, 2019, 2016, and older versions).
  • A basic understanding of how to click into a cell and type a formula.
  • A blank workbook or an existing sheet where you want the numbers to appear.

Step-by-Step

  1. Select Your Target Cell: Open your Excel workbook and click on the cell where you want the random 6-digit number to appear. If you need a list of numbers, you can select a single cell first and then drag the formula down later.
  2. Enter the RANDBETWEEN Formula: Type the following exactly as shown: =RANDBETWEEN(100000, 999999). The RANDBETWEEN function requires two arguments: the bottom boundary and the top boundary. By setting these to 100,000 and 999,999, you prevent Excel from generating a number with only 5 digits (which would happen if the bottom was 0).
  3. Press Enter: Once you have typed the formula, press the Enter key on your keyboard. Excel will immediately calculate a random number and display it in the cell.
  4. Fill Down for Multiple Numbers: If you need more than one 6-digit number, hover your mouse over the bottom-right corner of the cell until the cursor turns into a small black cross (the Fill Handle). Click and drag the handle down across as many rows as you need. Excel will apply the formula to every cell, generating a different random number for each.
  5. Convert Formulas to Static Values: It is important to know that RANDBETWEEN is a "volatile" function. This means every time you type in any other cell, press F9, or save the file, the numbers will change. To stop this and "freeze" your numbers:
    • Select all the cells containing the random numbers.
    • Right-click and select Copy (or press Ctrl+C).
    • Right-click on the same selection again.
    • Under Paste Options, select the icon that looks like a clipboard with "123" on it (Paste Values).
    Now the formulas are gone, and only the resulting 6-digit numbers remain.

Common Mistakes

One of the most frequent errors is using =RAND() instead of =RANDBETWEEN(). The RAND() function generates a decimal between 0 and 1 (e.g., 0.45231), which is not a 6-digit whole number. While you can mathematically manipulate RAND() to create a 6-digit number, it is unnecessarily complex for most users.

Another common mistake is setting the lower bound to 0 or 1. If you use =RANDBETWEEN(0, 999999), Excel might generate a number like "4521". While this is technically a number within that range, it only has four digits. To ensure a strict 6-digit count, the minimum must be 100,000.

Users also often forget to "Paste as Values." They spend an hour generating a list of IDs, only to find that the IDs have completely changed because they entered a new piece of data in a different part of the sheet. Always remember that volatile functions refresh on every calculation cycle.

Tips

If you need your 6-digit numbers to potentially start with a zero (e.g., "012345"), RANDBETWEEN alone won't work because Excel treats numbers as values and removes leading zeros. To achieve this, use the TEXT function to force a 6-digit format: =TEXT(RANDBETWEEN(0, 999999), "000000"). This converts the number into a text string and adds the necessary leading zeros to ensure the length is always exactly six.

To avoid duplicate numbers, RANDBETWEEN is not the best tool because it picks numbers independently; it is possible (though unlikely with a million options) to get the same number twice. If you need a list of unique random numbers, the best method in modern Excel (Office 365) is using the UNIQUE and RANDARRAY functions together. For example: =UNIQUE(RANDARRAY(100, 1, 100000, 999999, TRUE)). This generates 100 random numbers and filters out any duplicates automatically.

For those who prefer shortcuts, you can press F9 on your keyboard to manually trigger a recalculation of all random formulas in your sheet without having to edit a cell.

Troubleshooting

The number is showing as something like 1.23E+05: This is not an error; it is Excel's "Scientific Notation." This happens when the column is too narrow to display the full number. To fix this, hover your mouse over the right border of the column header (e.g., between column A and B) and double-click to auto-fit the width, or right-click the cell, select Format Cells, and choose Number with 0 decimal places.

The formula is appearing as text instead of a number: If you see =RANDBETWEEN(100000, 999999) inside the cell instead of a number, the cell is likely formatted as "Text." To fix this, select the cell, go to the Home tab, change the format dropdown from "Text" to "General," and then double-click the cell and press Enter to re-trigger the formula.

I get a #NAME? error: This usually means there is a typo in the function name. Check that you haven't misspelled RANDBETWEEN. Ensure there are no spaces between the function name and the opening parenthesis.

The numbers keep changing every time I click: As mentioned in the steps, this is the default behavior of the RANDBETWEEN function. The only way to stop this is to Copy the cells and Paste Values over the formulas.

Frequently Asked Questions

Can I generate a random 6-digit number that includes letters?

No, RANDBETWEEN only works with integers. To create an alphanumeric 6-digit code, you would need a complex formula using CHAR and RANDBETWEEN to pick random characters from the ASCII table, or use a VBA macro.

Does this work in Google Sheets?

Yes, the =RANDBETWEEN(100000, 999999) formula works exactly the same way in Google Sheets as it does in Microsoft Excel.

How do I make sure the numbers are not repeated?

The standard RANDBETWEEN does not check for duplicates. To ensure uniqueness, use the RANDARRAY and UNIQUE functions in Office 365, or generate a long list of random numbers, sort them, and use the Remove Duplicates tool under the Data tab.

Can I set the numbers to be only even or only odd?

Yes. For even numbers, use =RANDBETWEEN(50000, 499999)*2. For odd numbers, use =RANDBETWEEN(50000, 499999)*2+1. This ensures the result is always 6 digits and follows the parity you need.

Is there a limit to how many random numbers I can generate?

You can generate as many as your Excel row limit allows (1,048,576 rows). However, generating hundreds of thousands of volatile random numbers can slow down your computer's performance until you convert them to static values.