VBA: How to place array formula in a cell?

Egad

New Member
Joined
Oct 22, 2002
Messages
39
To manually place an array formula (like the one below) into a cell I use CTRL-SHIFT-ENTER.
=sum(if(b1:B100="Yes",c1:c100*d1:d100))

How would I do it thru vba? It doesn't seem to work like this:
cells(1,1).value=...formula...
 
On 2002-12-11 14:53, Egad wrote:
To manually place an array formula (like the one below) into a cell I use CTRL-SHIFT-ENTER.
=sum(if(b1:B100="Yes",c1:c100*d1:d100))

How would I do it thru vba? It doesn't seem to work like this:
cells(1,1).value=...formula...


I recorded an array formula with Recorder on
and it showed

Selection.FormulaArray = _
"=SUM(IF((R5C2:R103C2=RC[-6])*(R5C10:R103C10=RC[-5]),(R5C4:R103C6)))"

I would check .FormulaArray=
 
Upvote 0
Have a look at the FormulaArray property in VBA help. It's probably easier if you record yourself entering array formulae a few times, as it requires the use of R1C1 notation. In your case, placing the formula in cell E1 yields the following code: -
<pre>
Range("E1").FormulaArray = _
"=SUM(IF(RC[-3]:R[99]C[-3]=""Yes"",RC[-2]:R[99]C[-2]*RC[-1]:R[99]C[-1]))"
</pre>
 
Upvote 0
On 2002-12-11 15:00, Paul B wrote:
try this
Selection.FormulaArray = _
"=sum(if(b1:B100=""Yes"",c1:c100*d1:d100))"

:grin:, and there's me checking the helpfile which says you must use R1C1 notation. Don't believe everything you read in there...
 
Upvote 0
To make it a little interactive, try:
UserResponse = Chr$(34) & InputBox("Yes or No?") & Chr$(34)
Selection.FormulaArray = "=sum(if(b1:B100=" & UserResponse & ",c1:c100*d1:d100))"
 
Upvote 0
To make it a little interactive, try:
UserResponse = Chr$(34) & InputBox("Yes or No?") & Chr$(34)
Selection.FormulaArray = "=sum(if(b1:B100=" & UserResponse & ",c1:c100*d1:d100))"

Haha sound advice but I think you were out by about 7 years in this thread ;) lol good try though!!
 
Upvote 0
I am trying to enter an array formula in VBA but I have to use the R1C1 reference but it is not working. When I copy the formula over to another cell it changes all of my row and columns. Example is below.

Original formula:
{=SUM(IF('Timing Review'!C2=RC1,IF('Timing Review'!C11="Same Day",1,0),0))}

When I copy it through VBA the formula is becoming:
{=SUM(IF('Timing Review'!R[-2]C[-20]=R[-3]C[448],IF('Timing Review'!R[7]C[-20]="Same Day",1,0),0))}

Any suggestions?
 
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