Which formula can be used to prevent leading or trailing spaces in a data validation rule?
Which formula can be used to prevent leading or trailing spaces in a data validation rule?
Solution
The formula =TRIM(A1)=A1 is used to prevent leading or trailing spaces in data validation.
The TRIM function removes all leading and trailing spaces from text. When we compare TRIM(A1) with A1:
- If A1 has no leading or trailing spaces →
TRIM(A1)=A1→ Formula returns TRUE → Entry is allowed - If A1 has leading or trailing spaces →
TRIM(A1)≠A1→ Formula returns FALSE → Entry is rejected
For example:
- If user enters "Hello" → TRIM("Hello") = "Hello" → TRUE ✓
- If user enters " Hello" or "Hello " → TRIM will remove spaces → "Hello" ≠ " Hello" → FALSE ✗
The other options serve different purposes:
Option 2 (=LEN(A1)>10) checks if the text length exceeds 10 characters, not related to spaces.
Option 3 (=ISNUMBER(A1)) checks if the entry is a number, not related to spaces.
Option 4 (=WEEKDAY(A1)<>1) checks if a date is not Sunday, not related to spaces.
Related questions:
2022: 15 July Shift 2
2023: 11 June Shift 3
2025: 3 June Shift 1
2025: 4 June Shift 2
2025: 27 May Shift 1