How to create an array formula using VB

SCFM

New Member
Joined
Mar 2, 2010
Messages
10
I have the following array formula:
=SUM(B2:C2*B3:C3)
How should I asign this using Visual Basic? Thanks
 
It's not clear what you mean... you can calculate in memory using Evaluate, eg:

Code:
MsgBox Evaluate("SUM(B2:C2*B3:C3)")

or if you wanted to write back to Excel you could use the .FormulaArray property

Code:
Cells(1,"A").FormulaArray = "=SUM(B2:C2*B3:C3)"

However the same formula could be achieved using SUMPRODUCT which is not an Array.

Code:
=SUMPRODUCT(B2:C2,B3:C3)
 
Upvote 0
Why an array formula?

Are you sure whatever formula you want/need couldn't be done with a 'normal' formula?:)
 
Upvote 0
Why an array formula?

Are you sure whatever formula you want/need couldn't be done with a 'normal' formula?:)

My interest was about how to use/best way to use an array formula in VB. I utilized a test example. My real array formula is:

Cells(iRow, "H").FormulaArray = "=MAX(IF(ISNUMBER(0+MID(F" & iRow & ", 1, ROW($1:$4))),0+MID(F" & iRow & ",1,ROW($1:$4))))+IF(ISNUMBER(MATCH(RIGHT(F" & iRow & ",1),$I$2:$I$27,0)),VLOOKUP(RIGHT(F" & iRow & ",1),$I$2:$J$27,2,0)/10000,0)".

Regards
 
Upvote 0
FWIW the same formula can be achieved using non-array.

Using F2 as an example

=LOOKUP(9.99E+307,--MID(0&F2,1,ROW(1:5)))+SUMIF($I$1:$I$27,RIGHT(F2),$J$1:$J$27)/10000

I would also make the point that rather than applying a formula via iteration (as implied by use of iRow) you should apply the formula to a range en masse if viable, eg:

Code:
Range("H2:H100").Formula = "=LOOKUP(9.99E+307,--MID(0&F2,1,ROW($1:$5)))+SUMIF($I$1:$I$27,RIGHT(F2),$J$1:$J$27)/10000"
 
Upvote 0

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