how to include array variable in the formula?

novice_2010

Board Regular
Joined
Mar 18, 2010
Messages
105
I have following codes:

Sub test()
Dim ArrayVariable As Variant

Range("A1").Resize(1, 5).Name = "Range_Name_1"
Range("A5").Resize(5, 1).Name = "Range_Name_2"

Range("G1").Formula = "=mmult(Range_Name_1, Range_Name_2)"
Range("G2").FormulaArray = "=mmult(Range_Name_1, transpose(Range_Name_1))"

ArrayVariable = Range("A5").Resize(5, 1).Value
Range("J1").FormulaArray = "=mmult(Range_Name_1," & ArrayVariable & ")"

End Sub
I got a Type Mismatch error for the line in red. How to re-write this line of code? (ArrayVariable is a variable that contains a 5 by 1 array)
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hello,

Not real sure here. Try to use a msgbox arrayvariable. This could shed some light on what the arrayvariable is representing.

Also try .address instead of .value in the line above the red line.

-Jeff
 
Upvote 0
thank you very much. I followed your recommendation. Now the code works:

Sub test()
Dim ArrayVariable As Variant

Range("A1").Resize(1, 5).Name = "Range_Name_1"
Range("A5").Resize(5, 1).Name = "Range_Name_2"

Range("G1").Formula = "=mmult(Range_Name_1, Range_Name_2)"
Range("G2").FormulaArray = "=mmult(Range_Name_1, transpose(Range_Name_1))"

ArrayVariable = Range("A5").Resize(5, 1).Address
Range("J1").FormulaArray = "=mmult(Range_Name_1," & ArrayVariable & ")"

End Sub


Thanks again.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,289
Members
452,902
Latest member
Knuddeluff

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