Function Problems

Generate Permanent Unique Random Codes for New People in Excel

Phi Hung VoPhi Hung Vo Nov 12, 2026 869 views

Question details

Generate a list of unique random numeric codes for new people without duplicate values or unwanted recalculation changes.

Generate Permanent Unique Random Codes for New People in Excel
Product
Microsoft Excel
Device & OS
not provided
Scenario
The user needs 1,000 unique random four-digit codes to assign to new people.
Observed behavior
RANDBETWEEN can return duplicate values and changes its results whenever the worksheet recalculates.
Before you start

Use a version of Excel that supports dynamic array functions, including LET, RANDARRAY, UNIQUE, and TAKE. Select an empty cell with enough blank cells below it for the spilled list of codes.

Solution 1Recommended

Create unique random codes with a dynamic array formula

Use this method when you need a large set of unique random four-digit codes generated at once.

The formula generates more random candidates than needed, removes duplicates, and returns the first 1,000 unique values. Random functions are volatile, so convert the completed list to values when the codes must remain assigned permanently.

1
Select the first output cell

Click the empty cell where the first code should appear, such as A2. Ensure the cells below it are available for the spilled results.

2
Enter the unique-code formula

Type or paste =LET(numbers,RANDARRAY(4000,,1000,9999,1),TAKE(UNIQUE(numbers),1000)) and press Enter.

3
Confirm the spilled code list

Excel fills 1,000 cells with unique whole numbers from 1000 through 9999. If the spill range is blocked, clear the obstructing cells and enter the formula again.

4
Make the generated codes permanent

Select the returned codes, press Ctrl+C, then use Home > Paste > Paste Values to replace the formula results with fixed code values.

Create unique random codes with a dynamic array formula
Codes are fixed after pasting values: After you paste values, the codes will no longer change when Excel recalculates the worksheet.
WPS Spreadsheets solution

Create and Preserve Unique Random Codes in WPS Spreadsheets

WPS Spreadsheets can generate a dynamic list of unique random codes with modern array formulas. Enter the formula in an empty cell, let the results spill into the worksheet, and paste values once the codes are ready for assignment.

  1. 1. Open the code worksheet: Open the workbook in WPS Spreadsheets and click an empty starting cell, such as A2.
  2. 2. Generate the code candidates: Enter =LET(numbers,RANDARRAY(4000,,1000,9999,1),TAKE(UNIQUE(numbers),1000)) and press Enter.
  3. 3. Check the spilled results: Verify that the formula returns 1,000 unique four-digit codes and that no cells are blocking the output range.
  4. 4. Paste codes as values: Select the generated list, choose Home > Copy, then select Home > Paste > Paste Values to keep the assigned codes unchanged.
Generate unique random numeric codes for new people in one formula.Use dynamic array functions to remove duplicate random values automatically.Open and edit Microsoft Excel .xlsx files with format compatibility.Use a familiar spreadsheet interface for formulas, copy actions, and Paste Values.
microsoft office alternative - wps office

Frequently Asked Questions

Why does RANDBETWEEN create duplicate codes?

RANDBETWEEN generates each value independently, so it does not check whether a number was already returned. Use UNIQUE around a larger random array to remove repeated results.

Why do my random codes change when I edit another Excel cell?

RANDARRAY and RANDBETWEEN are volatile functions that recalculate with workbook changes. Select the finished codes, then use Home > Paste > Paste Values to keep them fixed.

Can I generate more than 1,000 unique codes?

Yes. Change the final 1000 in TAKE(UNIQUE(numbers),1000) to the number of codes you need, and increase the RANDARRAY row count if necessary.

What should I do if Excel shows a spill error?

Check the cells below and beside the formula cell for existing content, merged cells, or table boundaries. Clear the blocked range or move the formula to an empty area.