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 locked 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!
16 thoughts on “How do I lock certain cells in a formula in Google Sheets?”
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.
If I understand you correctly, whenever a field requires a range you can simply click and drag that range in.
Hey bro, this helps me a lot. Thanks for the useful information. Cheers! 🙂
You’re welcome, Jo. Glad you found it useful.
This was exactly what I needed, and I enjoyed your humor. Thanks!
I’m glad you found it helpful and a little fun. 😊
Thank you, you saved me today!
Slightly different problem. Lets say D1 has “=B1” but I then want to move the value of B1 to A1 and type a new value into B1. My problem is that D1 will now say “=A1” I get why that’s needed and handy, I just want a way to turn that off and to lock the formula of D1 to “=B1”
You might have better luck using the INDIRECT function here. In your example give this a go:
This really helps me how to lock one cell when applying multiple formula in google sheets, really thank you!
Hey! Having an issue with this. I’m trying to track inputs from the most recent week, 2 weeks, month, etc. So I want values fixed to a specific range of cells. For a week, it’s sum=(A2:A8)/7. For two weeks, it’s sum=(A2:A15)/14.
But whenever I add the new row for a new day, the formulas adjust. So it becomes sum=A3:A9)/7. etc.
I tried the Absolute Reference, but when I added the new row it still adjusted the values from A2:A8 to A3:A9.
Hmm… that shouldn’t occur. What does your absolute reference look like? This: sum=($A$2:$A$8)/7
Feel free to share an example.
Thanks for the tip. The F4 formula was what I had been looking for! Awesome blog.
Great to hear.