array formula via VBA

eykanal

New Member
Joined
Feb 16, 2005
Messages
3
Howdy folks -

I'm trying to get the following excel array formula to work in VBA:

Code:
=SUM(IF($P$2:$P$63=R2,1,0))/2

The problem is, the static references change from use to use. So, for example, while the above code would be fine for one sheet, it may be:

Code:
=SUM(IF($P$2:$P$88=R2,1,0))/2

on another. This is all fine if I use regular MyRange.End(xlDown) stuff, but the documentation (and all my stinking error messages) tell me that I need to use R1C1 format to create an arrayformula via VBA. My question is: how can I generate a R1C1 reference via VBA?

Thanks!
 

Some videos you may like

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Cbrine

Well-known Member
Joined
Dec 2, 2003
Messages
3,196
If think your looking for this.

activesheet.Range("a1").FormulaArray ="=SUM(IF($P$2:$P$63=R2,1,0))/2"

HTH
Cal
 

eykanal

New Member
Joined
Feb 16, 2005
Messages
3
That's what I have, but that won't work if the range changes (see my first post to see that the absolute references will change between worksheets).
 

Greg Truby

MrExcel MVP
Joined
Jun 19, 2002
Messages
10,014
Not tested, but I'm thinking something like:

[A1].FormulaArray = "=SUM(IF(" & Range(myRange, myRange.End(xlDown)).Address(True, True, xlR1C1) & "=R2C18,1,0))/2"
 

Watch MrExcel Video

Forum statistics

Threads
1,122,806
Messages
5,598,188
Members
414,218
Latest member
speedbit

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
Top