Google Sheets custom functions

Calculate six rows with one custom formula

A workshop coordinator has two columns for each review request: minutes requested and minutes already covered. All requests use the same slot length. How many more slots does each request need?

Download the Apps Script functions · Download the six practice rows (CSV)

Try both formulas in a blank Sheet

  1. Import the practice CSV into a blank spreadsheet so the two headers are in A1 and B1. Put 15 in F2 for the shared minutes per slot.
  2. Choose Extensions → Apps Script. Open the downloaded .gs file in a text editor, paste its contents into the blank project's Code.gs and save. Both custom functions calculate from their arguments.
  3. In C2 enter =REVIEW_SLOTS(A2,B2,$F$2) and fill it down through C7. This creates one scalar formula for each request.
  4. Leave D2:D7 empty. Enter =REVIEW_SLOTS_RANGE(A2:B7,$F$2) in D2. The function receives the two columns together and returns one column that fills D2:D7.
RequestedCoveredExtra 15-minute slots
45152
15150
empty0empty
3103
000
60153

The function leaves an incomplete request blank. A real zero means the request is covered. A request for 31 uncovered minutes takes three 15-minute slots because the last minute still needs a slot.

Check a blocked result

  1. In the practice Sheet, remove the formula from D2. Enter Reserved in D5. Put the range formula back in D2.
  2. D2 now shows #REF! and D5 keeps its text. If the text is needed, move it outside the output range. Clearing D5 in this exercise restores all six outputs.
  3. Change F2 to 30. Both columns should read 1, 0, blank, 2, 0, 2.

What Sheets actually ran

In our private test Sheet, Apps Script’s Executions page recorded six scalar calls and one range call when the formulas were first entered. It recorded the same counts when the shared slot length changed. The spill exercise added one range call. All 15 executions completed, even though Sheets displayed #REF! while an output cell was occupied.

Google gives custom functions 30 seconds to return. Combining rows can reduce calls to the Apps Script server. Execution time for your own data and code needs its own measurement. See Google’s custom-function optimization guide.