#REF when copying the result of a formula using VBA

eDarren

New Member
Joined
Sep 5, 2023
Messages
8
Office Version
  1. 365
Platform
  1. Windows
I have a few different sheets within one workbook, and i'm intending to have user defined data for cable calculations, when the data is input the user hits the calculate macro and VBA moves a bunch of things around to populate a Summary of the Calculations. I'm using some standard formulas within excel (for example =sum(I6/B1)) to perform some basic calculations. I then want to copy and paste the result of said formula into a seperate sheet which I intend to be a Summary of all the Calculations, making it more human readable and less jargon. My issue is, that when I do a copy/paste in VBA, I end up with a #REF because it's copied the formula from the previous sheet, but the new sheet doesn't have any of the values in the boxes that it's looking for....

My question is, how do I copy the result of a formula (=sum(I6/B1) into a seperate sheet set? I want this so be performed via a macro, so somebody clicks a "calculate" button when they are ready to, rather than automatically calculating using standard excel formulas.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
I do it by using a variant array as the intermediate, which defaults to values only
VBA Code:
Sub test()
Var = Worksheets("Sheet2").Range("B3:D5")
Worksheets("Sheet3").Range("B3:D5") = Var
Note you can do it using copyvalues but actually it takes rather more typing that using a varaint array
 
Upvote 0
Solution
I do it by using a variant array as the intermediate, which defaults to values only
VBA Code:
Sub test()
Var = Worksheets("Sheet2").Range("B3:D5")
Worksheets("Sheet3").Range("B3:D5") = Var
Note you can do it using copyvalues but actually it takes rather more typing that using a varaint array
Legend, that did it!
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,150
Members
453,021
Latest member
Justyna P

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