problem with relative references / anchoring when copying formulas from one range to another

pingpong777

New Member
Joined
Apr 6, 2015
Messages
42
Hi. I'm using this line:

Range("Scen_Active").Offset(0, (1 + Range("Scenario_Destination").Value)).Formula = Range("Scen_Active").Offset(0, (1 + Range("Scenario_Source").Value)).Formula

to copy scenario inputs from one column/scenario (numbered as Scenario_Source) to another (numbered as Scenario_Destination). I'm noticing an inconsistent issue- within this range (Scen_Active), I have a few cells which have formulas with the row anchored (=o$38 * 3; that sort of thing). Sometimes, the column letter remains an absolute reference, without any anchoring (for example, when trying to copy column P to column T, the formulas in column T will end up still referencing column P, even though they're written like (=P$38 * 3), with only the row number anchored.

Any ideas on what is tripping me up?


Thanks,

pingpong777
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi

You are using (range1.formula=range2.formula). This is reading the formula as as string from one range and writing it exactly equal in the second range.
There is no anchoring, the formula is copied exactly as is.

Maybe what you want

Code:
Range2.Copy Destination:=Range1

This is like the excel worksheet copy, the anchoring will be respected and the relative addresses are adjusted.

Another option is to copy only the formula, like:

Code:
Range2.Copy
Range1.PasteSpecial Paste:=xlPasteFormulas
 
Upvote 0
Hi @pgc01. Thanks! I think the first option that you outlined is what I want, as the range includes a mix or formulas and hardcoded values and I want to bring everything, including the formatting.

This site is awesome!
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top