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!
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
If think your looking for this.

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

HTH
Cal
 
Upvote 0
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).
 
Upvote 0
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"
 
Upvote 0

Forum statistics

Threads
1,213,497
Messages
6,113,999
Members
448,541
Latest member
iparraguirre89

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