VBA Copy / Paste array formula with relative references

davey4444

Board Regular
Joined
Nov 16, 2010
Messages
97
Hopefully the title explains this OK, I am using the following code to effectively copy and paste my array formula.

Code:
Dim CopyFrom1 As Range
Dim Lastrow As Long

Lastrow = Range("A" & Rows.Count).End(xlUp).Row
Set CopyFrom1 = ActiveSheet.Range("C3")
ActiveSheet.Range("C9").Resize(Lastrow).FormulaArray = CopyFrom1.FormulaArray

The array formula is -

Code:
=SUMPRODUCT(INDEX(Named_Range_1,MATCH(Upload!$A3,Named_Range_2,0),INDIRECT("1:43")),INDEX(Named_Range_3,MATCH(Upload!$B3,Named_Range_4,0),INDIRECT("1:43")))

How can I get the $A3 and $B3 to reference relative cells?

Thanks in advance.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
See if this produces the expected result:

Code:
Sub Relative()
Dim CopyFrom1 As Range, Lastrow&, s$
Lastrow = Range("A" & Rows.Count).End(xlUp).Row
s = "=SUMPRODUCT(INDEX(Named_Range_1,MATCH(Upload!A3,Named_Range_2,0)," & _
"INDIRECT(""1:43"")),INDEX(Named_Range_3,MATCH(Upload!B3,Named_Range_4,0),INDIRECT(""1:43"")))"
ActiveSheet.Range("c3").FormulaArray = s
Set CopyFrom1 = ActiveSheet.Range("C3")
ActiveSheet.Range("C9").Resize(Lastrow).FormulaArray = CopyFrom1.FormulaArray
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,464
Messages
6,055,578
Members
444,800
Latest member
KarenTheManager

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