To determine the value of the current cell based on the first digit of another specific cell, you can use an Excel formula that checks the first character of the referenced cell and returns 'xxx' or 'yyy' accordingly.
✅ Final Formula
=IF(LEFT(A1,1)="3","xxx",IF(LEFT(A1,1)="2","yyy",""))
🔍 Explanation
-
LEFT(A1,1):
- Extracts the first character from the value in cell
A1.
- This works whether the value is a number (e.g., 345) or a text string (e.g., "345").
-
IF(LEFT(A1,1)="3","xxx", ...):
- Checks if the first character is
"3".
- If true, returns
"xxx".
-
IF(LEFT(A1,1)="2","yyy",""):
- If the first character is not
"3", it checks if it's "2".
- If true, returns
"yyy".
- If neither, returns an empty string
"".
📝 Alternative Using SWITCH (Optional)
If you're using Excel 2016 or newer, you can use the SWITCH function for a cleaner approach:
=SWITCH(LEFT(A1,1),"3","xxx","2","yyy","")
SWITCH evaluates the expression LEFT(A1,1) and matches it to the listed values.
- If it finds
"3", returns "xxx".
- If it finds
"2", returns "yyy".
- If no match is found, returns
"".
📌 Notes
- Replace
A1 with the actual cell reference you want to evaluate.
- This formula assumes the cell contains a numeric value or a text string starting with a digit.
- If the cell is blank, or starts with any other character (e.g.,
"a", "4"), the formula will return an empty string ("").
- If you want to return a default message instead of an empty string for unmatched cases, you can add it at the end, e.g.,
"Other".
🧪 Example
| A1 | Formula Result |
|---|
| 345 | xxx |
| 23 | yyy |
| 45 | (empty) |
| abc | (empty) |
This formula provides a clean and effective way to conditionally return values based on the first digit of another cell.