Excel LET function: using variables inside a formula
Use Excel LET to name parts of a long formula: calculate a repeated piece once and make formulas readable and fast. Syntax, examples, naming rules and traps.
Look at this bonus formula: =ЕСЛИ(B2/C2>=1,2;B2*7%;ЕСЛИ(B2/C2>=1;B2*5%;0)). B2/C2 (plan achievement) is written twice. A formula like this is hard to read and risky to edit: it’s easy to change one place and forget the other.
LET lets you declare a variable inside the formula: “share means B2/C2”. From then on the formula uses just the name. The result is the same, but the formula is shorter and clearer, and Excel calculates the repeated part once.
LET brings programming-style variables to Excel. It works in Excel 2021 and Microsoft 365.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Manager | Sales | Plan | Bonus | |
| 2 | Aziz | 12 600 000 | 10 000 000 | 882 000 | |
| 3 | Dilnoza | 9 500 000 | 9 000 000 | 475 000 | |
| 4 | Javohir | 7 200 000 | 8 000 000 | 0 | |
| 5 | Madina | 11 000 000 | 9 000 000 | 770 000 | |
| 6 |
Syntax
=LET(name1; value1; [name2; value2; ...]; calculation)
- name1 — the variable name:
share,price,vat. - value1 — its value: a number, cell, range or formula (
B2/C2). - name2, value2, … — more pairs (up to 126). A later value can use earlier names.
- calculation — the last argument: the formula that produces the result, using the names.
Naming rules: start with a letter, no spaces; must not look like a cell reference (a1, xy12 are not allowed); the single letters r and c are reserved too. A name exists only inside its own formula.
Turning a regular formula into LET
1
First write the formula as usual and check the result. Then find the part that repeats — here it’s B2/C2.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Manager | Sales | Plan | Bonus | |
| 2 | Aziz | 12 600 000 | 10 000 000 | 882 000 | |
| 3 | Dilnoza | 9 500 000 | 9 000 000 | 475 000 | |
| 4 | Javohir | 7 200 000 | 8 000 000 | 0 | |
| 5 |
2
Start the formula with =LET( and name the repeated part: =LET(share;B2/C2; — name, comma, value, comma.
3
For the last argument, write the original formula but with share instead of B2/C2: IF(share>=1.2,B2*7%,IF(share>=1,B2*5%,0))). Press Enter — the result must match the old one.
4
Make a long LET readable: put each pair on its own line in the formula bar with Alt + Enter, and expand the formula bar with Ctrl + Shift + U.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Product | Price | Qty | With VAT | |
| 2 | Fridge | 6 500 000 | 2 | 14 560 000 | |
| 3 | TV | 4 200 000 | 3 | 14 112 000 | |
| 4 | Vacuum cleaner | 1 800 000 | 5 | 10 080 000 | |
| 5 |
| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Client | Rate | Years | Amount | Salary | Decision | |
| 2 | Aziz | 24% | 3 | 60 000 000 | 6 000 000 | Approve | |
| 3 | Dilnoza | 22% | 2 | 40 000 000 | 3 500 000 | Decline | |
| 4 | Javohir | 20% | 5 | 100 000 000 | 7 000 000 | Approve | |
| 5 | Madina | 18% | 1 | 20 000 000 | 3 000 000 | Decline | |
| 6 |
| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Manager | Sales | Branch | Branch: | Tashkent | ||
| 2 | Aziz | 8 500 000 | Tashkent | Result: | Count: 3, average: 9,066,667 | ||
| 3 | Dilnoza | 9 100 000 | Samarkand | ||||
| 4 | Javohir | 12 300 000 | Tashkent | ||||
| 5 | Madina | 4 200 000 | Samarkand | ||||
| 6 | Sardor | 6 400 000 | Tashkent | ||||
| 7 | Nodira | 7 800 000 | Bukhara | ||||
| 8 |
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Manager | Sales | Plan | Bonus | |
| 2 | Aziz | 12 600 000 | 10 000 000 | #NAME? | |
| 3 | Dilnoza | 9 500 000 | 9 000 000 | #NAME? | |
| 4 | Javohir | 7 200 000 | 8 000 000 | #NAME? | |
| 5 |
Pro level: speed, debugging and the road to LAMBDA
- Speed.
=ЕСЛИ(ISNA(ПРОСМОТРX(A2;Code;Price));0;ПРОСМОТРX(A2;Code;Price)*B2)runs the lookup twice.=LET(n;ПРОСМОТРX(A2;Code;Price);ЕСЛИ(ISNA(n);0;n*B2))runs it once. On a 100,000-row table the difference is noticeable. - Step-by-step debugging. If the result is wrong, return an intermediate name instead of the last argument:
=LET(share;B2/C2;share)shows whether share is calculated correctly. Then put the calculation back. - Settings in one place.
=LET(rate;7%;threshold;1,2;ЕСЛИ(B2/C2>=threshold;B2*rate;0))— the numbers sit at the start of the formula, with names. When the terms change, it’s obvious what to edit. - With dynamic arrays.
=LET(d;ФИЛЬТР(A2:C100;C2:C100>0);СОРТ(d;3;-1))— filter first, then sort; every step has a name. - Next step: LAMBDA. A LET formula can become your own function with
LAMBDAand be called anywhere in the workbook through Диспетчер имён, like=BONUS(B2;C2)(Microsoft 365).
Try it in the simulator
The simulator doesn’t calculate LET, so write the equivalent without it: type =ЕСЛИ(B2/C2>=1,2;B2*7%;ЕСЛИ(B2/C2>=1;B2*5%;0)) in D2 and fill down to D5. Compare with the LET table above — the results must match (882,000, 475,000, 0, 770,000).
| A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Manager | Sales | Plan | Bonus | ||||||||||||||||||||
| 2 | Aziz | 12600000 | 10000000 | |||||||||||||||||||||
| 3 | Dilnoza | 9500000 | 9000000 | |||||||||||||||||||||
| 4 | Javohir | 7200000 | 8000000 | |||||||||||||||||||||
| 5 | Madina | 11000000 | 9000000 | |||||||||||||||||||||
| 6 | ||||||||||||||||||||||||
| 7 | ||||||||||||||||||||||||
| 8 | ||||||||||||||||||||||||
| 9 | ||||||||||||||||||||||||
| 10 |
Has ExcelLab been useful?
Support the project and help us release new lessons and exercises.