To generate random numbers in Excel without duplicates, use a combination of the RAND, RANK, and ROW functions or the newer SORTBY and SEQUENCE functions in Excel 365. This method ensures each number in your list is unique, which is essential for tasks like drawing lottery winners, assigning random tasks, or creating test data. You must have a range of cells where you want the numbers to appear, and your version of Excel must support dynamic arrays if using the modern approach.
What You'll Need
- Microsoft Excel 2019 or later (for SEQUENCE and SORTBY functions) or Excel 2007+ (for the legacy RAND + RANK method)
- A blank column or range of cells where the unique random numbers will appear
- A clear idea of the range of numbers you want (e.g., 1 to 50, or 100 to 200)
Step-by-Step
- Decide how many unique random numbers you need. For example, if you want 20 unique numbers between 1 and 100, prepare a column with 20 rows ready.
- In the first cell of your target column (e.g., A1), enter the formula:
=RAND(). Press Enter. This generates a random decimal between 0 and 1. - Copy the formula in A1 down to all other cells in your target range. For 20 numbers, drag from A1 to A20. Each cell now holds a unique random decimal.
- In the adjacent column (e.g., B1), enter the formula:
=RANK(A1,$A$1:$A$20,1). This ranks the random value in A1 compared to the entire range of random decimals. - Copy the RANK formula from B1 down to B20. Each row now shows a rank from 1 to 20, corresponding to the order of the random values — effectively giving you a shuffled sequence with no duplicates.
- Once the ranks appear, select the entire range of ranks (B1:B20), right-click, and choose Copy.
- Select the same range (B1:B20), right-click again, and choose Paste Values to convert formulas to static numbers. This prevents the numbers from changing every time the sheet recalculates.
- Delete the helper column (A1:A20) if you no longer need it. You now have 20 unique random numbers between 1 and 20.
If you’re using Excel 365 or Excel 2021, there’s a faster method using dynamic arrays:
- In the first cell of your target column (e.g., A1), enter:
=SORTBY(SEQUENCE(20),RANDARRAY(20)). - Press Enter. This single formula generates a sequence of numbers from 1 to 20, then randomly sorts them using a matching array of random values.
- The result is 20 unique random numbers in a single step with no helper columns needed.
- These numbers will recalculate when the sheet updates. To lock them, copy the results and paste as values, just like in the legacy method.
Common Mistakes
- Using RAND() alone without RANK or SORTBY — this only gives random decimals, not integers and no guarantee of uniqueness.
- Forgetting to paste values after generating the sequence, causing numbers to change every time you edit the sheet or press F9.
- Using a range that’s too small for the number of outputs — for example, trying to generate 30 unique numbers between 1 and 25 is impossible and will cause errors or duplicates if forced.
- Referencing the wrong range in the RANK function. The range in RANK must be absolute (e.g., $A$1:$A$20), not relative. If you use A1:A20 without dollar signs, the range changes as you copy the formula down, breaking the ranking.
- Using the SEQUENCE function in older Excel versions — it will return a #NAME? error because SEQUENCE is only available in Excel 365 and Excel 2021.
Tips
- Always use Paste Values after generating your random list if you want to preserve it — otherwise, every time Excel recalculates (e.g., opening the file, editing another cell), the numbers will reshuffle.
- To generate random numbers in a custom range (like 50 to 100), modify the SEQUENCE formula to:
=SORTBY(SEQUENCE(20,,50),RANDARRAY(20)). The middle argument (50) sets the starting number. - Use named ranges for your input size to make formulas reusable. For example, name cell D1 as “Count” and enter your desired number of outputs. Then use:
=SORTBY(SEQUENCE(Count),RANDARRAY(Count)). - For non-consecutive numbers (e.g., random selection from a list of names), combine INDEX with this technique. Use SEQUENCE to generate unique indices, then use INDEX to pull from your list.
- Test your output: use COUNTUNIQUE (Excel 365) or a helper column with COUNTIF to verify each number appears only once. For example, in C1 enter:
=COUNTIF(B:B,B1)and drag down — every result should be 1.
Troubleshooting
- If you see #SPILL! error in Excel 365, it means the output range is blocked by existing data. Clear the cells below or to the right of your formula cell.
- If you get #NAME? error, you’re likely using an older version of Excel. Switch to the RAND + RANK method instead.
- If duplicates appear, you probably didn’t use an absolute reference in the RANK function. Double-check that the range in RANK is written as $A$1:$A$20, not A1:A20.
- If random numbers keep changing and you want them to stay fixed, you must paste as values. There is no setting to disable RAND() recalculations — it’s by design.
- If your random numbers are not integers, you likely used RAND() without RANK. RANK converts the random decimals into whole-number ranks. If you need a custom range of integers, use SEQUENCE with SORTBY.
- If Excel freezes or responds slowly with large ranges (e.g., 10,000+ numbers), the RANDARRAY function may be too heavy. Use the legacy method with a helper column and copy-paste values in batches.
Frequently Asked Questions
Can Excel generate random numbers without duplicates between 1 and 1000?
Yes, use=SORTBY(SEQUENCE(1000),RANDARRAY(1000)) in Excel 365. For older Excel, use RAND in column A (1000 rows), then RANK in column B with absolute reference to the range.
Why do my random numbers change every time I open the file?
RAND and RANDARRAY recalculate on every worksheet change or open. To keep them fixed, copy the results and paste them as values using Paste Special > Values.Can I use this method to randomly assign people to groups?
Yes. List names in column A, generate unique random numbers in column B using the method above, then sort the entire list by column B. The order will be randomized, and you can split the list into groups by row count.What if I need random numbers that aren’t consecutive, like 10, 25, 40, 55?
Use INDEX with SEQUENCE. For example:=INDEX({10,25,40,55},SORTBY(SEQUENCE(4),RANDARRAY(4))). This picks values from your custom list without duplicates.
Does this work on Excel for Mac?
Yes, if you’re using Excel 365 or Excel 2021 for Mac. The SEQUENCE and SORTBY functions are supported. Older versions require the RAND + RANK method.Can I generate random letters or text without duplicates?
Not directly with this method. But you can assign numbers to text items (1=A, 2=B, etc.), generate unique random numbers, then use INDEX to convert them to text. For example:=INDEX({"John","Jane","Bob"},SORTBY(SEQUENCE(3),RANDARRAY(3))).