How to Add Comments Within Google Sheets Formulas

This guide will explain how to add your own comments within a Google Sheets formula.

When working with complex formulas in Google Sheets, you may need to annotate these formulas with an explanation or comment of what the formula is for and what it calculates.

While Google Sheets does not have built-in support for in-line comments which is possible in programming languages such as Python or JavaScript, there are a few workarounds you can use.

In this guide, we will provide a step-by-step tutorial on how to use the N function and the LET function to add comments to your Google Sheets formulas.

The Anatomy of the N Function

The syntax of the N function is as follows:

=N(value)

Let’s look at each argument to understand how to use the N function.

  • = the equal sign is how we start any function in Google Sheets.
  • N() refers to our N function. This function allows us to return the argument provided as a number.
  • value argument refers to the value you want to convert into a number. 
  • If the value is not a number, N returns a value of 0.

The Anatomy of the LET Function

The syntax of the LET function is as follows:

=LET(name1, value_expression1, [name2, …], [value_expression2, …], formula_expression )

Let’s take a look at each argument to understand how to use the LET function.

  • = the equal sign is how we start any function in Google Sheets.
  • LET() refers to our LET function. This function allows us to assign an identifier for an expression we can use in another formula.
  • name1 refers to a name to assign to a particular expression.
  • value_expression1 refers to the formula we will refer to in the formula_expression argument.
  • name2… and value_expression_2… are optional arguments. The user can choose to add multiple assigned names for multiple value expression arguments.
  • The formula_expression argument  refers to the formula to be calculated. 

A Real Example of Adding Comments Withing a Google Sheets Formula

Using the N Function

Let’s explore a simple example where we can use the N function to add comments in Google Sheets formulas.

In the table above, we have a spreadsheet containing sales data for two products we’re selling.

Each row pertains to a particular date and product and specifies the quantity of that product sold on that day and the price it was sold. Using this data, we want to determine the total sales of each product.

To do this, we can use the following formula:

=SUMPRODUCT((B2:B7=F2)*(C2:C7)*(D2:D7))

The SUMPRODUCT function above calculates the total sales by multiplying each pair of quantity and price and adding their products. The B2:B7=F2 will allow us to control which product to calculate depending on what product name is placed in cell F2.

In our example above, we can see that our SUMPRODUCT formula in cell F3 calculates the total sales of product A. Similarly, our formula in cell G3 calculates the total sales of product B.

We can add a comment about what this formula does by adding a comment with the N function:

=SUMPRODUCT((B2:B7=F2)*(C2:C7)*(D2:D7)) + N("This formula returns the total sales of the product in cell F2")

The N function in the formula above includes a helpful comment that describes what the formula calculates.

Since N returns 0 if the user adds text as input, we were able to include an in-line comment to our formula without affecting the final output.

Using the LET Function

We can also use the LET function to add in-line comments:

=LET(comment,"This formula returns the total sales of the product in cell F2",SUMPRODUCT((B2:B7=F2)*(C2:C7)*(D2:D7)))

The LET function sets our comment text as the value of our comment variable. Since the comment variable is not mentioned in our actual formula, the final output is also not affected.

Click on the link below to create your own copy of our examples.

Head to the next section to read our step-by-step tutorial on how to add comments within a Google Sheets formula.

How to Add Comments Within Google Sheets Formulas

  1. First, select an empty cell where you wish to write the formula.

    In this example, we’ll enter our formula in cell F3.
  2. Type the target formula into the formula bar.

    In this example, we’ll write a SUMPRODUCT function.
  3. If the formula returns a numerical value, we can use the N function to add an in-line comment. At the end of the formula, add a “+” operator and type “
    N(comment).

    Replace the “comment” text with the actual comment you wish to include in your formula.

    Hit Enter to evaluate the function.
  4. We can also use the LET function to add comments to formulas. Start by selecting the empty cell and typing “=LET(comment,comment_text)”.

    Replace the comment_text argument with the actual comment enclosed in double quotes.
  5. Next, type the actual formula to evaluate as the third argument of the LET function.

    Hit the Enter key to evaluate the entire formula.

FAQs

  1. What should I do if the formula returns a text output instead of a numerical output?
    If your formula returns a text output, we recommend replacing the “+” operator with the “&” operator. The formula should also wrap the N function with the T function to ensure that the data types of the comment and formula output match.

To learn more about working with formulas in Google Sheets, you can read our post on how to automatically refresh formulas in Google Sheets.

That’s all for this guide! Don’t forget to check out our library of spreadsheet resources, tips, and tricks for both Google Sheets and Microsoft Excel! 

Get emails from us about Excel.

Our goal this year is to create lots of rich, bite-sized tutorials for Excel users like you. If you liked this one, you'd love what we are working on! Readers receive early access to new content.

0 Shares:
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like