alanhather

New Member
Joined
Feb 2, 2018
Messages
24
Hi -

Im trying to enter an array formula into VB if possible - i know the formula is too big but struggling to get it to work.

the formula im using is entered in Cell C180 and looks like this.

=SUM(--(FREQUENCY(IF('Raw Data Prev Year'!$B:$B<>"",IF('Raw Data Prev Year'!$D:$D=A171,IF('Raw Data Prev Year'!S:S>=$B$168,IF('Raw Data Prev Year'!$S:$S<=$C$168,MATCH('Raw Data Prev Year'!$B:$B,'Raw Data Prev Year'!$B:$B,0))))),ROW('Raw Data Prev Year'!$B:$B)-ROW('Raw Data Prev Year'!$B$1)+1)>0))

it is used to count an unique Alphanumeric ID within a specific date range and name and it only counts the alphanumeric ID once if it is a duplicate. As im doing a few calculations it can take a while to calculate but i do get the result.

Is this possible to run in VB or is there a way i can use as a countif?

thanks in advance
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
This is ugly and cumbersome but its the only way to get a long array formula into a cell via VBA i know of:

Code:
aaa = "=SUM(--(FREQUENCY(IF('Raw Data Prev Year'!$B:$B<>"""",IF(bbb,IF(ccc,IF(ddd,MATCH('Raw Data Prev Year'!$B:$B,'Raw Data Prev Year'!$B:$B,0))))),ROW('Raw Data Prev Year'!$B:$B)-ROW('Raw Data Prev Year'!$B$1)+1)>0))"
bbb = "'Raw Data Prev Year'!$D:$D=A171"
ccc = "'Raw Data Prev Year'!S:S>=$B$168"
ddd = "'Raw Data Prev Year'!$S:$S<=$C$168"

With Range("C180")
    .FormulaArray = aaa
    .Replace "bbb", bbb
    .Replace "ccc", ccc
    .Replace "ddd", ddd
End With
 
Upvote 0
Thanks for the help i'll give it a try now. - Do you think this could be done as a Count if function at all or is it too complex?
 
Upvote 0
Sorry do i need to use this as a sub? something like Sub ArrayFormula then put End sub at the end?

Thanks
 
Upvote 0
Well yes its code. You asked for VBA. You also need to be in the correct sheet when you run it, ie the sheet where you want it placed.
 
Upvote 0
Thanks worked really well this did. Is there a way though to use dates from another sheet? I have created a control sheet with cells with the dates on it so the year changes each time automatically.

The array formula doesnt seem to like using this and only likes a cell with the date typed in.

Looks like this

01/01=today() 'this is for the year=YEAR(D3) 'for the year=A1&"/"&$A$3
31/01
01/02

<tbody>
</tbody>

This is so i don't have to change the dates each time and pre set up.

thanks
 
Upvote 0
Heres how to build a date that changes when the year changes. I think thats what you mean.

=DATE(YEAR(TODAY()),1,1)

That will produce 1st Jan of current year.
 
Upvote 0

Forum statistics

Threads
1,214,990
Messages
6,122,625
Members
449,093
Latest member
catterz66

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