Formula Array Not working with variables

bendy315

New Member
Joined
Dec 21, 2009
Messages
7
I'm trying to use a formula array to do some calculations..

this works..
Range("C" & LastRow + 4).Select
Selection.FormulaArray = _
"=PERCENTILE(IF(L2:L" & LastRow & "=""15"",AC2:AC" & LastRow & "),0.4)"

but when I try to replace the 15 with a variable (year) it just returns a zero or #Value
Range("C" & LastRow + 4).Select
Selection.FormulaArray = _
"=PERCENTILE(IF(L2:L" & LastRow & "=" & year & ",AC2:AC" & LastRow & "),0.4)"


help! thanks.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
What type of variable is year?

Your use of 15 in the first version that works is as a string. If year is not a string variable, then that may be the cause of the zero result or error.
 
Upvote 0
It's the quotes...

Say LastRow = 10, your first code translates like this
"=PERCENTILE(IF(L2:L" & LastRow & "=""15"",AC2:AC" & LastRow & "),0.4)"
"=PERCENTILE(IF(L2:L" & 10 & "=""15"",AC2:AC" & 10 & "),0.4)"
"=PERCENTILE(IF(L2:L10=""15"",AC2:AC10),0.4)"

Now If
LastRow = 10
Year = 15

Your 2nd code translates like this
"=PERCENTILE(IF(L2:L" & LastRow & "=" & year & ",AC2:AC" & LastRow & "),0.4)"
"=PERCENTILE(IF(L2:L" & 10 & "=" & 15 & ",AC2:AC" & 10 & "),0.4)"
"=PERCENTILE(IF(L2:L10=15,AC2:AC10),0.4)"

Notice the missing double quotes on the 15

Try
"=PERCENTILE(IF(L2:L" & LastRow & "=""" & year & """,AC2:AC" & LastRow & "),0.4)"
 
Last edited:
Upvote 0
trying to use the same syntax for a different array formula in the same code. This one seems to not return anything. just null value in the cell.. can't seem to figure this one out either...

Range("H" & LastRow + 4).Select
Selection.FormulaArray = _
"=COUNTIFS(L2:L" & LastRow & ","" = """ & year & """"",AC2:AC" & LastRow & ","" <= """ & std & """"") / count"

lastrow=6, year =15, std = 700, & count=2. so answer should be 0.5 based on the data.

L AC
Year Hours
15 530
15 1,106
16 80
16 468
17 687

any thoughts...?
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

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