Moving from VBA to a formula

jerH

Board Regular
Joined
Dec 3, 2008
Messages
168
I've been working on a project for a while for a friend...he's into horse racing. I know zilch about horses...

There's a file that you can purchase, and my friend does, that for each day at a given track has historical data for the past ten races for each horse that is running that day. They're big .csv files, with ~1400 fields per line. The code I've written parses the file and then, using some formulas he has created, produces a handicapping report to guide his bets.

So far everything has worked well, but his latest request has me a bit stumped. Here's the basic situation.

Part of the report has a column for each horse called EP (early pace) and MP (middle pace). A sample might look like

EPMP
7783
8891
8993
8586
100105
6764

<colgroup><col span="2"></colgroup><tbody>
</tbody>

He wanted a add a column that is a calculated speed metric. It works like this:
Average the EP and MP.
For the horse with the maximum average, enter a positive number that is how far ahead of the next best
For the remaining horses, enter a negative number that is how far behind the best

So for the above data, the new column looks like this

-22.5
-13.0
-11.5
-17.0
+11.5
-37.0


<colgroup><col span="3"></colgroup><tbody>
</tbody>

This shows that the fifth horse had the best average, and was 11.5 better than the next best horse (which was number 3). Number 3 had the second best and is 11.5 behind the best. Number 2 was next best, and was 13 behind the best, and so on.

I have this all implemented in code and it works fine. The issue is that sometime horses scratch and don't race. For every other field in the report this is no big deal, you simply delete the row that corresponds to that horse and everything is fine. At worst, conditional formatting highlights the new max value/top 3/etc in the column. But since this column relies on the values of the other horses to calculate, deleting a horse can completely change the values. If, for instance, the fifth horse (best) scratched, then the number 3 horse is now the best, and his entry should change to +1.5. Horse 2 would be second best and so his entry would become -1.5, etc.

The only way I can see to make that happen is if, rather than calculating the values and populating the cells, I populate the cells with a formula using calculated ranges...but I'm nowhere near proficient enough is rank, index, etc to make that happen. Particularly since what we're ranking is a value that never even appears on the sheet (the average of EP and MP). I guess I could drop those values to the sheet way off to the right where they're outside the print area and no one ever sees them. Then have an if that does one thing for rank 1 and something else for all the others....but I'm still not sure how to use rank, index, etc to pull that off.

Any help?

Thanks in advance.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,214,524
Messages
6,120,049
Members
448,940
Latest member
mdusw

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