jueves 16 de octubre de 2008

Excel: copy the exact content of cells

Here a couple of tips to copy the exact content/formula of a range of cells in Microsoft Excel. First some introduction and later the tricks

Some thoughts...
As you probably know, Excel has a lot of possibilities in terms of copy cells (copy only values, formula, create a reference to the other cell, transmute the content, etc).
But when you copy a formula in fact excel keeps the relative references (what is in general the expected behaviour)...
Excel has a different behaviour if you move the cells (Cut&Paste), then it moves the formula as it is without changing the references.

Trick 1
1. Select and copy (Ctrl+C) the range of cells you want to copy. (we call this area: range1)
2. Use an empty region of the sheet to paste (Ctrl+V) that content temporally. (we call this area: range2)
3. Select again the original region (range1) but this time move the cells to the region you want to copy the exact formulas. (Ctrl-X, Ctrl-V)
4. And now copy back the cell range in point 2. (what we called region2) back to the original region (range1).

... and you have it (just remove the temporal region range2).
Update: I have detected a problem doing this, the formulas accessing the original cells get messed up.

Trick 2
This one use VBA macro script to copy the formulas:

With Sheets("Sheet1")
.Range("A11:D20").Formula = .Range("A1:D10").Formula
End With

(source: Excel User Tips)