You know, I’m pretty confident in my use of Google Sheets. I use a lot of its 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.
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 aspects 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 won’t 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,
- Click a cell or range you want to get a value from and you want to lock or make an Absolute Reference.
- Press <F4> until you get the desired Absolute Reference combination.
- 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:
Let’s plug in the formula to count the total number of Bananas.
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:
More examples of COUNTIF
Just for a lark, let’s see how that COUNTIF formula will work if I drag it down with that cheeky little box in the bottom right of the cell.
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.
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.
- entered: =COUNTIF(
- selected the range C2:c13
- hit the magical <F4> button once and it created: $C$2:$C$13
- entered a comma: ,
- selected the range E3
- closed the bracket: )
- hit <enter>
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.
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.
Just to be pear-dantic (Hey! That was okay!) let’s see how guilty we should be for our fruit binge.
$38.10? Worth it!