VBA: Copying Formulas and Array Formulas at the same time

Omom

New Member
Joined
Jan 25, 2013
Messages
7
Hi,

I am struggling with the following code, that in essence is trying to copy a range of formulas from one sheet to another:

Code:
Sub CopySheetToSheet()
Dim r, c As Integer
Dim rngA As Variant

'HC Reference to Sheet5 Range Alpha
Set rngA = Sheet5.Range("Alpha")
r = rngA.Rows.Count
c = rngA.Columns.Count

Sheet7.Range("A1").Resize(r, c).FormulaArray = rngCF.FormulaArray

End Sub

When I amend the code that copies from rngA (Sheet 5) to Sheet7 by replacing the ".FormulaArray" Function with ".Formula" it works perfectly fine. Effectively it copies the entire range of Sheet 5 to Sheet 7. However, in rngA there are a number of rows with ArrayFunctions which I need to bring over to Sheet 7. As soon as I run the code as posted above (with the FormulaArray Function) a blank Sheet 7 is returned (i.e. the code seems to copy blanks from rngA to Sheet 7 and not the functions within rngA).

Further I need this to be dynamic - the code is supposed to copy rngA to a large number of Sheets (Sheet 7, 8, 9... and so on). So it needs to be fast (probably by-passing the clipboard ?). Last but not least - can rngA be defined as range as opposed to a variant ?

Any explanation what I am missing is greatly appreciated.
Thanks in advance.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Apologies - there was a mistake in my code (marked in red). See correction below:
Code:
Sub CopySheetToSheet()
Dim r, c As Integer
Dim rngA As Variant

'HC Reference to Sheet5 Range Alpha
Set rngA = Sheet5.Range("Alpha")
r = rngA.Rows.Count
c = rngA.Columns.Count

Sheet7.Range("A1").Resize(r, c).FormulaArray = [COLOR=#ff0000][B]rngA[/B][/COLOR].FormulaArray

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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