Need to optimize VBA code using array formula

ikauai

New Member
Joined
Jul 22, 2011
Messages
10
I have the following code run by a macro to populate a cell with the value of an array formula using the evaluate function. The formula works but it rather slow and I have several of them in a row that need to execute.

ActiveSheet.Range("O4").Value = Evaluate("MEDIAN(IF(E:E=M3, IF(I:I>0,I:I, 0)))")

Is there any way to make this run faster with an alteration or different procedure? Right now I have about 30 of them and it takes a couple of minutes to run, which is way too long for my purposes.

any help would be appreciated
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
As I already said in a couple of other topics today: use a pivot table for these kind of calculations. Do not use array formulas for these operations.
 
Upvote 0
Pivot tables cannot handle and do not provide the median formula (which I specified in my question) as an aggregate function. I have to resort to the array formula on the sheet or via vba. All other functions are fine such as average, sum, count etc but my report needs require median as well.
 
Upvote 0
Perhaps you could alter the formula to use specific ranges rather than entire columns?
 
Upvote 0
Thanks, that did help a bit with the time to process. Needed to used a finalrow variable to set a dynamic range. Just getting back into this..

thanks for your help :-)
 
Upvote 0
I actually did a quick search on Median and pivot tables, and yes it isn't available as one of the standard aggregrate functions.

Howevert here was a lot of stuff about how to deal with the problem, workarounds, formulas, add-ins etc.

Mostly they were specific situations, or the examples were anyway, but it's probably worth taking a look.

You might get some ideas about code and/or the actual formula itself.

Actually, I was going to suggest you write your own UDF, but I'm not 100% sure what your formula is doing.

Looks a bit more complicated than a 'simple' median calculation.

Might even be an idea to ask here for help with the formula itself.
 
Upvote 0
My bad, I thought the median was provided in a pivot table. Apologies.
 
Upvote 0

Forum statistics

Threads
1,224,579
Messages
6,179,656
Members
452,934
Latest member
mm1t1

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