Formulas
Write calculations with references, suggestions, and spreadsheet errors.
Write a calculation
Select a cell and enter a formula beginning with = in the cell editor or formula bar. Use commas between function arguments, periods for decimal numbers, and double quotes around text.
Enter numeric values without quotes so they are stored as numbers and included by functions such as SUM; quoted values are text.
=A1+B1
=SUM(B2:B20)
=IF(C2>100, "Over budget", "On track")
Press Enter on the completed expression. The grid shows its result; the formula bar keeps the expression. See the function reference for the supported function set and tested examples.
The formula bar's name box navigates to a cell or range; see editing and sheets for address navigation and imported-row behavior.
Cell and sheet references
A1 refers to a cell on the current sheet. A1:B3 is a rectangular range. Use a sheet name followed by ! for another sheet. Quote names containing spaces; escape an apostrophe with a second apostrophe.
=Sheet2!A1*2
='Sales 2026'!A1
='Bob''s Data'!A1
Absolute-reference spellings such as $A$1, A$1, and $A1 are accepted. During fill, relative row and column parts move with the destination, while absolute parts stay fixed. A shifted reference outside the worksheet becomes #REF!. Text such as "A1" is a string, not a reference, and remains unchanged during fill. See editing and sheets for fill controls and imported-row behavior.
Inside a text literal, write a double quote twice to include one quote in the result. For example, ="He said ""hi""" returns He said "hi". A missing closing quote produces #PARSE!.
Use suggestions and reference selection
While typing a function name after =, suggestions appear. Use the Up/Down arrows to select a suggestion and Tab or Enter to insert it. Complete its arguments and closing parenthesis, then press Enter to commit.
Function signatures show required and optional arguments; square brackets indicate optional arguments and are not characters to type. Clicking a cell or dragging a range while editing a formula inserts that reference. The same color identifies each cell reference in the formula draft, reference tags, and matching grid highlight. Text inside quoted strings is not highlighted. Press Escape to cancel the formula session.
Operators and compatibility
Arithmetic supports +, -, *, /, %, and exponentiation written as **. Parentheses control evaluation order. Comparisons include =, <>, <, <=, >, and >=. Boolean literals are TRUE and FALSE.
Hugtab implements a constrained formula language, not every Excel function or expression. Conversion of blanks, text, and booleans depends on the function; read its behavior notes. IF evaluates only its chosen branch, so =IF(TRUE, 7, 1/0) returns 7. IFERROR catches a typed formula error in its first argument and evaluates the optional fallback only when needed; for example, =IFERROR(1/0, 7) returns 7. If the fallback is omitted, a handled error returns a blank.
For SUM, COUNT, AVERAGE, MIN, and MAX, cell and range references count numeric cell values only; referenced text, booleans, and blanks are ignored. Direct numeric-looking text and boolean arguments are converted to numbers. Direct nonnumeric text returns #VALUE! for SUM, AVERAGE, MIN, and MAX, while COUNT ignores it. COUNT ignores formula errors in referenced cells; the other four functions propagate them. A numeric date serial participates as a number.
COUNTA counts zero-length text, including a cell formula such as ="", as a value. A truly blank cell is not counted; repeated references are counted each time, and whitespace is text.
Date functions
DATE(year, month, day) returns a numeric date serial. It truncates decimal
arguments, treats years from 0 through 1899 as 1900 through 3799, and normalizes
month and day overflow into adjacent dates. For example, =DATE(2024,2,29)
returns 45351 and =DATE(2024,13,1) returns the serial for 1 January 2025.
Years outside 0–9999 and results before serial 0 return #NUM!.
YEAR, MONTH, and DAY extract calendar parts from a nonnegative numeric
serial or ISO date text such as "2024-02-29". A serial's fractional time is
ignored; serial 0 represents 30 December 1899. These functions return #NUM!
for negative serials and #VALUE! for other text. Date formulas use the
workbook's numeric serial model; cell display formatting is separate.
=DATE(2024, 2, 29)
=YEAR(DATE(2024, 2, 29))
=MONTH(45351)
=DAY("2024-02-29")
Text extraction and replacement
LEFT and RIGHT return characters from either end of a value; their optional count defaults to 1. MID uses a one-based start and a required character count. Zero counts return empty text, while negative counts and a MID/FIND start below 1 return #VALUE!. Numeric text and booleans are accepted as index values (TRUE is 1); fractional counts are truncated. These functions convert the source value to text, with blanks becoming empty text and booleans becoming TRUE or FALSE.
FIND returns the one-based position of the first case-sensitive match. Its optional start defaults to 1; a missing match returns #VALUE!. SUBSTITUTE replaces every case-sensitive match, or just the one-based occurrence supplied as its optional fourth argument. An occurrence below 1 returns #VALUE!; a number beyond the matches leaves the text unchanged. An empty search string leaves the source text unchanged.
Text positions follow Google Sheets' UTF-16 indexing. A supplementary Unicode character such as an emoji occupies two positions; a substring that selects only half of its surrogate pair is returned with the replacement character, matching Sheets' visible result.
=LEFT("Hugtab", 3)
=RIGHT("Hugtab", 3)
=MID("Hugtab", 2, 3)
=FIND("g", "Hugtab")
=SUBSTITUTE("a-b-a", "a", "x", 2)
Conditional counts and sums
COUNTIF(range, criterion) and SUMIF(range, criterion, [sum_range]) apply one condition. COUNTIFS(criteria_range1, criterion1, …) and SUMIFS(sum_range, criteria_range1, …) require every condition to match; these multi-range functions require all ranges to have the same shape. SUMIF anchors sum_range at its top-left cell and pairs values across the criteria range's full shape, even if sum_range is smaller. Text comparisons ignore letter case; criteria can use =, <>, <, <=, >, and >= operators. * matches any number of characters and ? matches one; prefix either wildcard or a tilde with ~ to match it literally.
=COUNTIF(A2:A8, "Paid")
=SUMIF(A2:A8, "Paid", B2:B8)
=COUNTIFS(A2:A8, "Paid", B2:B8, ">=10")
A blank criterion matches blank cells and zero-length text. Numeric equality criteria match equivalent numeric text; ordered numeric criteria compare numeric cells and ignore text and formula errors. An error can be matched by its displayed code, such as "#DIV/0!". SUMIF and SUMIFS ignore referenced text, booleans, and blanks in the sum range, but propagate a formula error when a matching row selects it. These functions scan ranges in the formula engine without expanding imported data into workbook cells.
TRIM removes leading and trailing ordinary spaces and reduces repeated ordinary spaces between words to one. Tabs, line breaks, and non-breaking spaces are preserved.
Exact lookups
VLOOKUP, INDEX, and MATCH work with ordinary cell references and ranges, including quoted cross-sheet references. VLOOKUP searches the first column from top to bottom and returns the first exact, case-insensitive text match. Set its fourth argument to FALSE; that argument is required because approximate matching is unsupported. A missing key returns #N/A, and a result column outside the table returns #REF!.
MATCH searches a one-dimensional row or column and returns the first matching position. Set its search type to 0; that argument is required because approximate search types are unsupported. A missing key or a two-dimensional search range returns #N/A. INDEX takes a required, one-based row position and returns one cell. Its column position is optional for a one-column range. Zero positions and omissions that would produce an array result return #VALUE!; an index outside the range returns #REF!.
ARRAYFORMULA(range) returns one bounded same-sheet cell or rectangular range as a spill result on ordinary sheets. For example, entering =ARRAYFORMULA(A4:B5) in A1 displays the source values in A1:B2. The anchor formula owns the derived output; editing a precedent recalculates it, while undo/redo and reload rebuild the result from the anchor. A non-empty target blocks the whole result with #REF!. Results are limited to 10,000 grid positions. Selecting a spill child is allowed, but editing or clearing it is rejected; edit or clear the anchor instead. Formatting a child changes that coordinate and does not block the result.
This is a deliberately narrow subset: array output is unsupported on imported-data sheets, and whole-column references, cross-sheet input ranges, cross-sheet spill destinations, arbitrary array algebra, dynamic references, and other array functions are not supported. CSV and XLSX exports contain current scalar values rather than the array formula or ownership metadata.
=VLOOKUP("Banana", A1:B3, 2, FALSE)
=INDEX(A1:B3, MATCH("Banana", A1:A3, 0), 2)
Lookup ranges are accessed cell by cell, so a search does not copy the whole referenced range into workbook cell storage. For large imported tables the formula engine still reads the scanned lookup column until the first match; keep the lookup range as narrow as the task allows.
Formula errors
| Display | Meaning / next step |
|---|---|
#NAME? |
Unknown function or name; check the reference. |
#PARSE! |
Unsupported or malformed expression; check commas, quotes, and parentheses. |
#REF! |
Invalid sheet or cell reference; check the source. |
#CYCLE! |
A formula depends on itself, directly or indirectly; break the cycle. |
#DIV/0! |
Division by zero or an average with no numeric values. |
#VALUE! |
A value cannot be used by this calculation. |
#NUM! |
A number or date is outside the function's supported range. |
#N/A |
An exact lookup key was not found, or MATCH received a two-dimensional range. |
Formula errors propagate through direct cell references and ranges. A text value that begins with # stays text unless the source cell contains a formula error. Changing a precedent recalculates its affected dependents using their current formulas; unrelated formulas keep their results, and undo/redo recalculates them with the restored value. Imported Excel-only expressions may remain editable but show an error.