Skip to content
GridBelt
  • Excel Test
  • Practice
  • Programs
  • Pricing
Sign in
Start the free test
  • Excel Test
  • Practice
  • Programs
  • Pricing
Sign inCreate account
Start the free test
GridBelt

Practice Excel in your browser.

Excel Test

  • Level 1: Beginner
  • Level 2: Intermediate
  • Level 3: Expert
  • Excel test in 7 days
  • Leaderboard
  • Excel test for interview
  • Indeed Excel assessment

Practice

  • All exercises
  • Programs
  • For beginners

Guides

  • Excel formulas
  • Excel shortcuts

Company

  • About
  • Pricing
  • How we grade

© GridBelt. All rights reserved.

  • Privacy Policy
  • Terms of Use
  • Refund Policy

Excel is a trademark of Microsoft Corporation. Indeed, TestGorilla, SHL and other marks are the property of their owners. GridBelt is an independent practice site and is not affiliated with, endorsed by or sponsored by Microsoft, TestGorilla, SHL or Indeed.

  1. Practice
  2. /
  3. IF function

IFERROR practice: margin % for 50 products without #DIV/0!

  • Intermediate
  • ~6 min
  • IF function

The buying team maintains a price list of 50 products with the unit cost (column D) and the selling price (column E). They report margin on cost — how much the selling price exceeds the cost, as a percentage of the cost: (price − cost) ÷ cost. 4 promotional items were received free from a supplier, so their cost is 0 and the division has no answer. The report must show n/a on those rows instead of an error, because the column is summarised further down the chain.

What you need to do

  1. 1Click F2. The unit cost is in D2 and the selling price in E2; the margin on cost is (E2-D2)/D2.
  2. 2Wrap the division in IFERROR: the first argument is the calculation, the second is what to show when it fails — the text "n/a" in quotes.
  3. 3Press Enter and fill F2 down to F51 (double-click the fill handle, or select F2:F51 and press Ctrl+D / ⌘D). The column is already formatted as a percentage.
  4. 4Scroll to the promotional items (cost $0.00): they must read n/a, not #DIV/0!. Then click Check (Ctrl+Enter / ⌘+Return).

Answer cells

Feedback

Type your formula in the grid, press Enter, then Check. We grade the value in each answer cell and the formula behind it.

Tasks

  1. Not checkedIn F2, calculate the margin on cost, (E2-D2)/D2, so that the zero-cost rows show "n/a" instead of #DIV/0! — IFERROR is the usual tool — then fill the formula down to F51.

Desktop recommended for spreadsheet tasks. The sheet scrolls inside this box.

StartInsertFormulasDataView
A1fxPreparing your workbook…
A
B
C
D
E
F
G
H
I
J
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Sheet1

Enter your formula in the sheet, then check.

About this exercise

A 50-row dataset on one sheet, one answer cell, about 6 minutes. Graded in your browser: the value and the formula behind it, with feedback that names the fix.

How to solve it

  • F2=IFERROR((E2-D2)/D2,"n/a")

Dividing by an empty or zero cost raises #DIV/0!, and one error cell is enough to break every AVERAGE or SUM that reads the column. IFERROR(value, value_if_error) returns the first argument when it computes normally and the second when it produces any error, so =IFERROR((E2-D2)/D2,"n/a") shows the margin for priced items and n/a for the four free ones. Filled down, the same formula handles every row without you knowing in advance which products have a zero cost.

Pitfall 1: IFERROR hides every error, not just #DIV/0! — a typo like (E2-D2)/D3 or a text value in column E is silently replaced by n/a too. When only the zero-cost case is expected, =IF(D2=0,"n/a",(E2-D2)/D2) is the more honest formula; IFERROR is the pragmatic choice when the data can hold several kinds of junk. Pitfall 2: returning 0 or "" instead of n/a changes the statistics — AVERAGE ignores text but counts a 0, so a 0% margin on free stock drags the average down. Pitfall 3: margin on cost (markup) is not margin on price: (E2-D2)/E2 never divides by zero here and gives a different, smaller number; always state which one a report uses. Alternatives: IFNA only catches #N/A (useful around lookups, useless here); in Excel 365, =LET(m,(E2-D2)/D2,IF(ISERROR(m),"n/a",m)) avoids computing the division twice. Formatting: the fallback text sits in a column formatted 0.0% — text ignores number formats, which is why n/a shows as typed.

Other ways that work

  • =IF(D2=0,"n/a",(E2-D2)/D2) — explicit test on the cost; only the expected error case is handled
  • =IF(ISERROR((E2-D2)/D2),"n/a",(E2-D2)/D2) — the pre-2007 pattern IFERROR replaced
  • =IFERROR(E2/D2-1,"n/a") — algebraically the same margin on cost

Common mistakes

Writing =IFERROR((E2-D2)/D2) with no second argument, or putting the fallback first — IFERROR needs the calculation first and the replacement value second, in quotes when it is text.

How we grade

Any formula that produces the right result is accepted, unless the task names a function: then another function earns half credit. We compare values with a small tolerance and ignore case and spaces in text. A correct number typed by hand instead of a formula earns half credit. Multi-cell tasks earn full credit at 100% of cells, half credit from 50%. Where it matters, we also change an input cell on a copy of your sheet and check that your formula follows.

Answers computed with Excel 365 rules and checked in our grading engine on November 16, 2026. Author: GridBelt team.

In these programs

  • Excel for Data AnalystsDay 4
  • Excel for Accounting and BookkeepingDay 3
  • Learn Excel From ScratchDay 10

Related exercises

  • Flag rows with missing dataIntermediate, ~5 min
  • Commission tiers with nested IF, IFS or a lookupIntermediate, ~8 min
  • Pass or Fail with IFBeginner, ~4 min

Function reference

Official documentation

Next exercise

Commission tiers with nested IF, IFS or a lookup