Home » How to Create and Use Variables in Google Sheets

How to Create and Use Variables in Google Sheets

by Erma Khan

The easiest way to create variables that you can reference in formulas in Google Sheets is to use the Name box to give custom names to cells.

The following example shows how to do so in practice.

Example: Create and Use Variables in Google Sheets

Suppose we have the following information about the number of units sold, the unit price, and the unit cost for some store:

To calculate the total revenue for this store, we can use the following formula:

Total Revenue = Units Sold * (Unit Price – Unit Cost)

We could type the following formula into cell B4 to calculate this value:

=B1*(B2-B3) 

The following screenshot shows how to use this formula:

From the output we can see that the total revenue is $60.

However, we could also create variable names for the cells and then use the variable names in the formula to calculate the total revenue.

To do so, click on cell B1. Then click the Name box in the top left corner:

Then type any custom name you’d like.

For this example, we’ll type units_sold and then press Enter:

We’ll repeat this process with cell B2 and B3, using the names unit_price and unit_cost as the variable names.

Now we can type the following formula into cell B4 to calculate the total revenue, using only the variable names in the formula:

=units_sold*(unit_price-unit_cost)

The following screenshot shows how to use this formula:

From the output we can see that the total revenue is $60.

This matches the value that we calculated earlier using the cell references in the formula.

Note that in this scenario we used a simple formula that only involved three variables, but in practice you can give custom names to as many cells as you’d like so that you can use as many variable names in a formula that you need.

Also note that the variable names we defined on one sheet can be used in a different sheet within the same Google Sheets workbook.

Additional Resources

The following tutorials explain how to perform other common tasks in Google Sheets:

How to Use a MULTIPLY IF Function in Google Sheets
How to Use a RANK IF Formula in Google Sheets
How to Use Standard Deviation IF in Google Sheets

Related Posts