How do I lock certain cells in a formula in Google Sheets?

You know, I’m pretty confident in my use of Google Sheets. I use a lot of it’s advanced features and formulas in my daily work.

But one thing was bugging me. Every time I created a formula and then grabbed and dragged (or double clicked) that little box in the bottom right of the cell to have it repeat, the cells would change.

The little square down the bottom of the cell

This normally is great, because it moves by a cell each time and makes my life easier.

What if I want to keep a certain cell constant in a formula?

Enter the Absolute Reference.

The absolute reference allows you to lock either or both aspect of the cell. That is it can lock the column and/or the row. This is done by simply adding a “$” before the column or row. Here is how we do it:

  • $A$1 – locks both Column and Row
  • $A1 – locks only the Column
  • A$1 – locks only the Row

Awesome!!! Now you can drag that little square wherever you want and whatever part of that cell you locked wont change while everything else will.

F4 – The Shortcut From the Gods

So, this is all well and good, but it still means that after I have finished entering the whole formula, I have to go back into the cell and change the cell value with that dollar sign “$”.

F4 to the rescue. You can change the value live here by cycling through $A$1, $A1 and A$1 before continuing with your formula. While completing a formula simply,

  1. click a cell or range you want to get a value from and you want to lock or make an Absolute Reference.
  2. Press <F4> until you get the desired Absolute Reference combination.
  3. Continue with the rest of your formula.

Example – My Fruit Binge

I really love fruit (Okay, I’m ambivalent about fruit, but I am trying to sell the example here!)

I have a list of fruit that I have eaten in the last hour. My wife has caught me with a pile of cores and skins scattered around me and wants me to count how much this food binge cost me in order to make me feel bad.

Of course, I immediately run to my laptop and bring up my list of fruit I just ate. I can also remember how much each item costs (Yep, the example is breaking here, stay with me).

To work out the total costs of what I ate, I will count how many of each item and multiply that by the costs of each item.

Here is my Google Sheet so far:

Fruit Google Sheets

 

Lets plug in the formula to count the total number of Bananas.

Google Sheets Countif

 

Things look good so far. In cell G3 I have run countif and selected the range C2:C13. And I only want it to count if the cell contains the text “Banana” which I indicate by cell E3. Finally, in cell H3 I multiply the total number of times Banana appears (G3) by the cost of the item (F3).

The end results:

Google Sheets Fruit absolute reference error

Just for shits and giggles, lets see how that countif formula will work if I drag it down with that cheeky little box in the bottom right of the cell.

Fruit google sheets no absolute reference.

As you can see things have gone a bit Pear-shaped (nailed it!) here. We can see 2 pairs in the list in column C but the formula is only counting one in cell G7. 

Let’s take a look at the formula in G7.

countif reading wrong cells

We can see here that the range has changed from C2:C13 to C6:C17. That is not helpful at all. We need to make these into an Absolute Reference. The fruit criterion also moved, but we wanted it to come down to read Pear so that is pear-fict (Not so good that time).

Let’s fix this up. We need to change the countif range in cell G3 to an Absolute Reference from C2:C13 to $C$2:$C$13. This is kinda awkward so let’s try that <F4> shortcut out and put in the formula again fresh. To do this I did the following steps.

  1. entered:  =COUNTIF(
  2. selected the range C2:c13
  3. hit the magical <F4> button once and it created: $C$2:$C$13
  4. entered a comma:   ,
  5. selected the range E3
  6. closed the bracket: )
  7. hit <enter>Google Sheets Absolute reference with F4

Looks good. We’ll grab that little box down the bottom again and drag (or double click) it down and see if we get that extra pear.

Absolute reference in use

Boom! It worked. We now see 2 pears counted. Check out that bottom cell. It’s lock in the range value and only changes the fruit criterion.

Absolute reference view of final cell

Just to be pear-dantic (Hey! That was okay!) let’s see how guilty we should be for our fruit binge.

Fruit binge total google sheets

$38.10? Worth it!

 

 

 

 

 

4 thoughts on “How do I lock certain cells in a formula in Google Sheets?”

  1. Hi, thanks for the infos. Do you know how to grab and drag with the mouse a single cell inside a formula?
    When you want to move a single value inside a formula but you don’t want to type the new coordinates with the keyboard.
    Thanks

    1. If I understand you correctly, whenever a field requires a range you can simply click and drag that range in.

Leave a Reply