Excel VBA: copying a cell with FormulaR1C1

zeno

Board Regular
Joined
Feb 16, 2012
Messages
71
I receive an run-time error message 1004 "autofill method of range class failed" in the following setting, in the 2nd line.
In this instance, I want to copy 1 cell from the cell 2 columns before.

Code:
     Range("M3").FormulaR1C1 = "=RC[-2]"
     Range("M3").AutoFill Destination:=Range("M3"), Type:=xlFillDefault

Thank you for your help.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Do you mean

Code:
     Range("M3").FormulaR1C1 = "=RC[-2]"
     Range("M3").AutoFill Destination:=Range("L3:M3"), Type:=xlFillDefault
 
Upvote 0
I actually only want to copy 1 single cell. Here, it would be copying in cell M3 the cell from 2 columns before, so cell K3.
For that reason I wrote "RC[-2] so that it should look for the cell from 2 columns before (-2).
Unless my interpretation is wrong? I cannot specify which column exactly, because this may change.
 
Upvote 0
Have you tried this?
Code:
Range("M2:M3").FormulaR1C1 = "=RC[-2]"
 
Upvote 0
Thank you for your responses. However, they put multiple fields (2) with that formula, instead of only 1 field. My objective is to only copy the value of 2 previous columns, in this example value of cell K3 copied to M3.
Is it possible to use FormulaR1C1 or should I use another code formula?
 
Upvote 0
If you want values in cells copied to other cells you can't use formulas.
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,720
Members
448,986
Latest member
andreguerra

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