Copying a value from a formula, from one sheet to another

Gwhaou

Board Regular
Joined
May 10, 2022
Messages
78
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hello I tried to use this code to copy all the data from the column P6:P (last line) from the sheet "Original" and paste it on another sheet called "Test", well actually those data from the sheet "Original" are values, which are sums values by using FormulaR1C1.

When I copy that on the sheet called "Test" from the Cell "H2", got error called #REF

This is the code :

VBA Code:
Sub Copy_Paste()

Dim lg As Long
lg = Sheets("Original").Range("A" & Rows.Count).End(xlUp).Row ' used to know the last row 

Sheets("Original").Range("P6:P" & lg).Copy Sheets("Test").Range("H2")

End Sub

1657120326340.png


This is the code used to make sums on the initial Sheet :

VBA Code:
Sheets("Original").Range("P6").FormulaR1C1 = "=RC[-8]+RC[-7]+RC[-6]"
Sheets("Original").Range("P6").AutoFill Destination:=Sheets("Original").Range("P6:P" & lg)


A little help would be appreciated 🙏
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Do you just want to copy the values?
 
Upvote 0
In that case you can use
VBA Code:
Sheets("Test").Range("H2").Resize(lg - 5).Value = Sheets("Original").Range("P6:P" & lg).Value
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,892
Messages
6,175,236
Members
452,621
Latest member
Laura_PinksBTHFT

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