How to Fix Excel Formula Returning FALSE When Assigning Random Numbers Based on Text
Question details
The user needs to correctly assign random numbers from specific ranges based on different text values without the formula returning FALSE.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Setting up a conditional formula to generate a random number from one range if a cell contains a specific word, and another range for a different word.
- Observed behavior
- The formula unexpectedly returns FALSE, failing to generate the random number even when the text visually appears to match the required condition.
Ensure the cell containing your target text does not have invisible characters, extra spaces, or cell formatting that prevents an exact match within your conditional formula.
Clean and Standardize Cell Text
Remove hidden spaces, quotation marks, or formatting errors in the referenced cell so the formula can recognize the text.
When an IF formula checks for a text string like "dog" but encounters "dog " (with a trailing space), it evaluates the condition as untrue. If no 'value_if_false' parameter is provided, Excel defaults to outputting FALSE.
Click the cell containing the text value (e.g., B32) and look at the formula bar.
Make sure the cell itself only contains the word (like dog or cat) and does not have typed quotation marks around it.
Place your cursor at the end of the text in the formula bar and press Backspace to remove any trailing spaces.
For large datasets, use =TRIM(B32) in an adjacent column to automatically strip out all leading and trailing spaces, then use this new cleaned column for your formula reference.

Correct the IF and RANDBETWEEN Formula Structure
Properly nest your logical conditions and random number generators to avoid unhandled FALSE outputs.
Seamlessly Handle Formulas and Clean Data in WPS Spreadsheet
WPS Office provides a highly compatible and intuitive spreadsheet environment for resolving formula errors, cleaning text data, and running complex conditional functions effortlessly.
- 1. Open your spreadsheet: Launch WPS Spreadsheet and open the file where your formula is returning FALSE.
- 2. Clean your target data: Use the TRIM function or the Find and Replace tool to remove accidental spaces from your text cells.
- 3. Input the correct formula: Enter your nested =IF() and =RANDBETWEEN() functions directly into the formula bar.
- 4. Verify your results: Press Enter to execute the formula and confirm that the numbers generate correctly based on the text criteria.

Frequently Asked Questions
Why does my IF formula return FALSE instead of calculating?
An IF formula returns FALSE when the condition you are testing is not met, and you have not provided a 'value_if_false' argument at the end of the formula. This frequently happens if the referenced text contains hidden spaces or typographical errors that make the match fail.
How do I generate a random number between specific values?
You can use the RANDBETWEEN function. For example, typing =RANDBETWEEN(1, 100) will return a random whole number between 1 and 100. It recalculates whenever the worksheet calculates.
Is the Excel IF function case-sensitive when checking text?
No, the standard IF function is not case-sensitive. It treats "Dog" and "dog" as the same value. If you need case-sensitivity, you must combine the IF function with the EXACT function, like =IF(EXACT(B32, "dog"), ...).
How can I easily remove extra spaces from an entire column?
Insert a new column next to your text, use the formula =TRIM(A1) (assuming A1 is your starting cell), and drag the fill handle down. Copy the newly trimmed column, and paste it as 'Values' over the original column to permanently remove the spaces.




