OK, I've got it that I can directly copy a row of formulas without using Select/Copy/Paste -
With range1 and range2 each set to a row:
This is clearly more efficient and cleaner that using the clipboard.
Problem is, the formulas are copied verbatim, with relative references not getting updated. I.e. if I have
and I use the direct copy method to copy this to row 2, I get
I would expect this to behave as when I copy/paste, i.e I would expect
Is there a way to get relative address updating in a direct copy? The best I've come up with is to modify my formulas using
INDEX(Sht, ROW(), COLUMN())
to refer to the cell itself (where Sht is a range referring to the whole sheet). Then I use OFFSET to get relative references. My B1 now becomes:
And when I use my direct copy I get the expected result. But for any by the simplest of formulas this becomes really messy.
The other disadvantage is that if I decide to insert a new column or move my columns around I have to update all my offsets manually.
There must be a better way! Anybody, please!
With range1 and range2 each set to a row:
Rich (BB code):
range2.formula = range1.formula
Problem is, the formulas are copied verbatim, with relative references not getting updated. I.e. if I have
Rich (BB code):
A1 is 2
B1 is =A1 * A1
Rich (BB code):
A2 is 2
B2 is =A1 * A1
Rich (BB code):
B2 to be =A2 * A2
INDEX(Sht, ROW(), COLUMN())
to refer to the cell itself (where Sht is a range referring to the whole sheet). Then I use OFFSET to get relative references. My B1 now becomes:
Rich (BB code):
=OFFSET(INDEX(Sht, ROW(), COLUMN()),0,-1) * OFFSET(INDEX(Sht, ROW(), COLUMN()),0,-1)
The other disadvantage is that if I decide to insert a new column or move my columns around I have to update all my offsets manually.
There must be a better way! Anybody, please!
