98

Google Sheets has a feature where if you have a reference to a data cell in a formula, and you cut the data from that cell and paste it in a new location, the reference in the formula is updated to point to the new cell location.

I'd like to be able to cut and paste my data without my formulas changing.

I've done some hideous things in the past involving the INDIRECT() function to work round this feature, but it seems like there's got to be an easier way. Any suggestions?

ale
  • 52,972
  • 42
  • 165
  • 314
grahamparks
  • 1,096
  • 1
  • 7
  • 7

20 Answers20

81

When you hover over selected cells and the cursor turns to a "hand", you can then drag the cells and preserve their references. Detailed instructions below:

From the Google Docs forum:

Select the range of cells. Then use Ctrl+C (copy; this should put the cells and their formulas in the paste buffer).

Now drag (hover over the edge of the selection until the mouse cursor changes into a hand; now you can drag) the selected cells to the new position.

Go back to the original top-left position of the copied cells and use Ctrl+V (paste).

Now you should have two sets of formulas both referencing the same cells.

marikamitsos
  • 13,110
  • 4
  • 35
  • 59
Matt McClure
  • 1,021
  • 8
  • 4
46

The =$A$1 notation can also be automatically moved if the value in (say) A1 is changed.

The only surefire solution is to enclose all your references in INDIRECT, e.g. =INDIRECT("$A$1") or even just =INDIRECT("A1").

The difficulty with either of these solutions is where you have many of the same formula, e.g.

=A1
=A2
=A3
...
=A99

Normally, you would fill in the first =A1 and then copy-and-paste (or drag down using autofill) to fill out the consecutive formula automatically. If, however the first formula is =$A$1 or =INDIRECT("A1") then this trick won't work (in fact, this is what $ is for - to prevent it being automatically changed).

If you have many consecutive formula, one solution is:

  1. Create the formula as you normally (use plain =A1 and autofill)
  2. Use the replace dialog (Ctrl+H) and use "search in formulas" to wrap all =A1, =A2 ... =A99 in the =INDIRECT("A1") etc. Note you have the option to use regular expressions when doing a find-and-replace.
marikamitsos
  • 13,110
  • 4
  • 35
  • 59
Motti Strom
  • 584
  • 5
  • 4
40

Came across this looking for a similar problem and ended up finding a solution for Excel which seems to work perfectly in the Google Spreadsheets.

For the cell references you don't want to change on paste simply add $ before each part.

So G12 would become $G$12

A cell from a spreadsheet I am using that does what I need, looks something like this:

 =$G$1&Sheet1!B3&Sheet1!A3&$G$2
marikamitsos
  • 13,110
  • 4
  • 35
  • 59
Leonard
  • 517
  • 1
  • 3
  • 3
15

In Google Spreadsheets, to cut and paste cells without auto-shifting their formulas, you use Ctrl + X to cut (or Ctrl + C to copy), and Ctrl + Shift + V to paste.

The Shift tells Google Sheets to leave your formulas alone.

ale
  • 52,972
  • 42
  • 165
  • 314
feisty penguin
  • 183
  • 1
  • 2
7

Here's another option:

  1. Switch to "Show formulas" mode (under the View menu)
  2. copy the desired area
  3. Paste in some external text editor
  4. Make some change - can be as simple as adding a space somewhere
  5. Copy the formulas from the external text editor
  6. Paste in the target area in the sheet
  7. Turn Show formulas off

While this seems like a long procedure, in practice it's merely a few key strokes. Also, step #4 is mandatory in my setup - without it Sheets will still update the cells locations as if it were a direct copy and paste. YMMV.

Eran
  • 189
  • 1
  • 4
7

Work around this the same way as in Excel:

COPY and paste the data, and then go back and delete it from the original place.

MaryC.fromNZ
  • 7,338
  • 1
  • 20
  • 31
5

Cut (instead of Copy) seems to work for me, probably for the same reason dragging selected cells works - i.e. it's the same operation. This is also the only way I know of to paste to another page without the formula changing.

If you're trying to do a Copy instead of a Move, either use the drag method (copy before dragging), or copy it somewhere else on the page first.

Peter Tseng
  • 151
  • 1
  • 3
4

Using INDIRECT() works great for preserving the absolute position of references after the targets have been copied and pasted, but the problem is that it also preserves the absolute position when the formula is copied, meaning that you can't easily extend a formula to cover a large range when using it.

The solution is to combine INDIRECT() with ROW(), COLUMN(), and ADDRESS() to programmatically generate the position of the target cell based on the formula's cell.

In the simplest case, such as when the target cell has a fixed column and always stays in the same row as the formula, this can be done as follows:

INDIRECT("A"&ROW())

In order to introduce dynamic offsets from the formula cell, you can use ADDRESS():

INDIRECT(ADDRESS(ROW()-1,COL()-4))

In the below screenshot, the formulae in the B1:E1 were extended to the 16 rows beneath, and then the number sequence in A7:A10 was cut and pasted 6 cells down. As you can see, the simplest formulae were automatically adjusted and desynchronized, while the naive use of INDIRECT() did not extrapolate across all rows properly, but the two formulae that use INDIRECT() along with programmatic retrieval of row and column locations were able to maintain their references:

Demonstration Picture

Will Chen
  • 141
  • 3
3

To move a range of cells to a new location in Google Sheets:

1. Select the range of cells you want to move
2. Move your mouse to any edge of the selection until the cursor changes into a hand
3. Drag your cells to the new location

This does what it should - it moves them - so all cell information will remain exactly as they were in their original location.

ps. Google has also instructed this here but they don't say you can drag from any edge, just the top one, and that is why my instruction is better! :) Also it's good to note that the cells you select need to be adjacent in order for this to work.

Dniz
  • 31
  • 2
2

I just Find and Replace all instances of '=' with '' (or as much of the formulas I'm trying to copy as I can) to make all the formulas into plain text. I copy and paste the cells, then add the '=' back.

Note: this probably won't work for huge sheets, as it can have unintended consequences by editing other cells, but it usually works for my purposes.

marikamitsos
  • 13,110
  • 4
  • 35
  • 59
Luke Redmore
  • 121
  • 1
1

Easiest way is to just select all of the cells you want to move and drag/drop to where you want them. If you have formulas in other cells that were referencing back to the original location of the cells you moved, the reference formulas will automatically update to the new location of the cells you moved. Hope this helps! (Assuming this works in Excel, but I've only done it in Google Sheets).

Danny
  • 21
  • 1
1

There are lots of solutions here already, but if your column-headers are stable you can use index() with row() and match(). Say the value you want will always be in a column with a [1st-row] heading of 'last month', then to find:

  • the column # you would: match("last month",$1:$1,0)
  • the row you would use (without any arguments): row()

So then your formula to get the value is (e.g. with 150 rows):

=index($1:$150, row(), match("last month",$1:$1,0))
Adam Smooch
  • 111
  • 3
1

Do a text copy of the formula instead of a cell copy: Use the mouse to select the formula text and press CTRL+C. Then select the destination field and press CTRL+V. This preserve the formula

0
  1. Select cells with mouse
  2. Copy co clipboard
  3. Move the selected cells to a new location with your mouse via capturing the edge of the group
  4. Paste from clipboard into the empty space you just moved everything away from
0

The best way I've been able to solve this problem is by creating a duplicate of the sheet on Google Sheets.

From the duplicate, I cut the cells and then paste them to the original sheet. I then delete the duplicated sheet.

Seems tacky, but saves me a lot of time.

Chris
  • 1
0

Here is a bit of hack, as previously noted, Ctrl+X for cut and then paste preserves the references (equations changed to refer to original cells from new location), it's copy and paste that updates according to the rules changing which cells are referred to). Using $s à la $A$1 version works within a sheet, but not between sheets.

So...

  1. Use Ctrl+X and Ctrl+V to cut and paste it to a new location (the equations will be modified to refer to the original locations). The problem is that then the original is gone.
  2. Copy (Ctrl+C) the new position
  3. Undo to restore the old (removing the new)
  4. Then Ctrl+V at the new location to put back the copy

Result table copied and all the equations are modified to refer to the same original cells, even on different sheets.

Rubén - Volunteer Moderator -
  • 46,305
  • 18
  • 101
  • 297
0

Simplest way:

  1. Show formulas -> View / Check Show Formulas
  2. Copy formulas (or cut) -> Ctrl + C | Ctrl + X
  3. Paste values -> Ctrl + Shift + V
  4. Hide Formulas -> View / Uncheck Show Formulas
serenesat
  • 10,042
  • 30
  • 34
  • 50
0

This "bug" seems to be a standard feature in all spreadsheets applications, and I know of no option to disable it, (though there are a few workarounds).

It's most irritating when you have an accounting ledger with a column of subtotals. When you cut and copy and item/amount row, the subtotal formulas get mixed up. Even if you "protect" the formula cells, they still get changed when you do this! It's very counter intuitive.

The trick of selecting and mouse-dragging doesn't work for me in Libre Calc.

What I always do by habit, as a safeguard, is Ctrl+C to cut my item/amount rows, then immediately hit Delete to remove them. Now there is no longer any reference between the amount cell and adjacent formula cell, and I can past the row in another location with issue.

Glorfindel
  • 2,379
  • 5
  • 19
  • 28
Matthew S
  • 1
  • 1
0

I think I found a super simple way. Instead of copying the cell. Click on the cell you want to copy and go to the fX bar and copy straight from there. The Cell references do not change.

-1

You can hit F4 to cycle through the various absolute referencing options when the cursor is on the cell or range. This works on Mac and Windows.

ale
  • 52,972
  • 42
  • 165
  • 314