Bird
Raised Fist0
Google Sheetsspreadsheet~10 mins

Custom functions in Google Sheets - Cell-by-Cell Formula Trace

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Sample Data

Column A has numbers. Column B uses a custom function DOUBLE to multiply each number by 2.

CellValue
A15
A210
A315
B1=DOUBLE(A1)
B2=DOUBLE(A2)
B3=DOUBLE(A3)
Formula Trace
=DOUBLE(A1)
Step 1: A1
Step 2: DOUBLE(5)
Cell Reference Map
    A     B
1 |  5  -> 10
2 | 10  -> 20
3 | 15  -> 30
Cells in column A are inputs to the custom function DOUBLE in column B.
Result
    A     B
1 |  5  | 10
2 | 10  | 20
3 | 15  | 30
Column B shows the doubled values of column A using the custom function DOUBLE.
Sheet Trace Quiz - 3 Questions
Test your understanding
What does the custom function DOUBLE do to the input number?
AMultiplies the number by 2
BAdds 2 to the number
CSubtracts 2 from the number
DDivides the number by 2
Key Result
Custom functions take input cell values and return results based on user-defined logic.

Practice

(1/5)
1. What is a custom function in Google Sheets?
easy
A. A chart type you add to your sheet
B. A built-in formula like SUM or AVERAGE
C. A filter to sort data automatically
D. A formula you create using JavaScript in Google Apps Script

Solution

  1. Step 1: Understand what custom functions are

    Custom functions are formulas you write yourself using JavaScript in Google Apps Script.
  2. Step 2: Differentiate from built-in features

    Built-in formulas like SUM are pre-made, while custom functions are user-created.
  3. Final Answer:

    A formula you create using JavaScript in Google Apps Script -> Option D
  4. Quick Check:

    Custom function = user-made JavaScript formula [OK]
Hint: Custom functions are your own formulas written in JavaScript [OK]
Common Mistakes:
  • Confusing custom functions with built-in formulas
  • Thinking custom functions are chart types
  • Believing custom functions are filters
2. Which of the following is the correct way to start defining a custom function in Google Apps Script?
easy
A. function MYFUNCTION() { return 'Hello'; }
B. def MYFUNCTION() { return 'Hello'; }
C. func MYFUNCTION() { return 'Hello'; }
D. function: MYFUNCTION() { return 'Hello'; }

Solution

  1. Step 1: Recall JavaScript function syntax

    In Google Apps Script, which uses JavaScript, functions start with the keyword 'function' followed by the name and parentheses.
  2. Step 2: Check each option's syntax

    function MYFUNCTION() { return 'Hello'; } uses correct JavaScript syntax. Options B and C use Python or other language syntax. function: MYFUNCTION() { return 'Hello'; } has incorrect punctuation.
  3. Final Answer:

    function MYFUNCTION() { return 'Hello'; } -> Option A
  4. Quick Check:

    JavaScript function syntax = function MYFUNCTION() { return 'Hello'; } [OK]
Hint: JavaScript functions start with 'function' keyword [OK]
Common Mistakes:
  • Using Python or other language syntax
  • Adding colons after function name
  • Missing parentheses after function name
3. Given this custom function code in Google Apps Script:
function DOUBLE(input) {
  return input * 2;
}

What will be the result of =DOUBLE(5) in a sheet cell?
medium
A. 5
B. DOUBLE(5)
C. 10
D. Error

Solution

  1. Step 1: Understand the function logic

    The function takes an input and returns input multiplied by 2.
  2. Step 2: Calculate the output for input 5

    5 multiplied by 2 equals 10.
  3. Final Answer:

    10 -> Option C
  4. Quick Check:

    5 * 2 = 10 [OK]
Hint: Multiply input by 2 to get output [OK]
Common Mistakes:
  • Expecting the function name as output
  • Thinking it returns input unchanged
  • Assuming syntax error without checking code
4. You wrote this custom function:
function ADDTEN(value) {
  return value + 10
}

But when you use =ADDTEN(5) in the sheet, it shows an error. What is the likely problem?
medium
A. Function name must be lowercase
B. Missing closing brace '}'
C. Function lacks parentheses
D. Missing semicolon after return statement

Solution

  1. Step 1: Check the function syntax carefully

    The function code is missing the closing brace '}' at the end.
  2. Step 2: Understand impact of missing brace

    Without the closing brace, the script is incomplete and causes an error when called.
  3. Final Answer:

    Missing closing brace '}' -> Option B
  4. Quick Check:

    All functions need matching braces [OK]
Hint: Always close function with a brace '}' [OK]
Common Mistakes:
  • Thinking semicolon is mandatory in Apps Script
  • Assuming function name case matters
  • Overlooking missing braces
5. You want a custom function that takes a range of numbers and returns the sum of only the positive numbers. Which of these custom functions will work correctly?
hard
A. function SUMPOS(range) { let total = 0; for (let i = 0; i < range.length; i++) { if (range[i][0] > 0) total += range[i][0]; } return total; }
B. function SUMPOS(range) { return range.reduce((a,b) => a + b); }
C. function SUMPOS(range) { let total = 0; for (let i in range) { if (range[i] < 0) total += range[i]; } return total; }
D. function SUMPOS(range) { return Math.sum(range); }

Solution

  1. Step 1: Analyze each function's logic

    function SUMPOS(range) { let total = 0; for (let i = 0; i < range.length; i++) { if (range[i][0] > 0) total += range[i][0]; } return total; } loops through the range and adds only positive numbers. function SUMPOS(range) { return range.reduce((a,b) => a + b); } sums all numbers without filtering. function SUMPOS(range) { let total = 0; for (let i in range) { if (range[i] < 0) total += range[i]; } return total; } adds negative numbers only. function SUMPOS(range) { return Math.sum(range); } uses a non-existent Math.sum function.
  2. Step 2: Identify correct filtering and summing

    Only function SUMPOS(range) { let total = 0; for (let i = 0; i < range.length; i++) { if (range[i][0] > 0) total += range[i][0]; } return total; } correctly filters positive numbers and sums them.
  3. Final Answer:

    The function that sums only positive numbers -> Option A
  4. Quick Check:

    Filter positive numbers, then sum [OK]
Hint: Loop and add only if number > 0 [OK]
Common Mistakes:
  • Summing all numbers without filtering
  • Adding negative numbers by mistake
  • Using non-existent functions like Math.sum