PDA

View Full Version : Solved: Summing to a target



silentsound
03-31-2011, 09:39 AM
Hi

I am trying to write a VBA application which takes a series of data and works out the closest way to sum to a given target. I have written such an application but once the number of data points increases beyond 20ish the run time of the application becomes incredibly long. The application I wrote mainly utilies Myna Larson's combinations code (should be able to find it easily on google).

I have tried the following approaches which have turned out to be useless:
a) Exiting the routine once a target was reached. I couldn't work out how to exit the sub due to the recursive nature of the Code
b) 'chopping' the data into chunks and summing to smaller targets, but the sums were too far from the smaller targets for the collective sum to obe close enough to the actual target.

I should also clarify that Myna Larson's code itself takes a long time to execute with the number of data points I am talking about. (roughly 120)

Any suggestions, or am I wasting my time? If I can't do it this way what should my approach be?

Any help much appreciated!!

mdmackillop
03-31-2011, 09:58 AM
Can you please post what you have? What tolerance is allowed or do you really require the closest possible?

silentsound
03-31-2011, 11:05 AM
Can you please post what you have? What tolerance is allowed or do you really require the closest possible?

Hi,

Thanks for the reply. The difficulty is that it's for work, so no, not really. I am really looking for as close as possible. The data is distributed within a range, mostly near a single point.

Sorry, I know there's not a lot to go on there. I am mainly looking for ideas, but if people have code, that's great.

silentsound
04-01-2011, 01:11 AM
Anyone?