Hi all, got a challenge
I have a loop running through my code.
I will not post the entire code, but it goes through millions of combinations, created from 15 columns filled with prices.
Each combination consists of 15 values (one value from each column)
Within these columns there are groups.
For example the values from the first two columns can be considered group1,
and the values used from column 3 to 7 can be considered group2
First I had to find the largest value in each possible combination within group 2 - which was doable for me like this:
However, after this I need to SUM the largest 3 of 5 values in group 2
Price3 = Cells(c, 51).Value
Price4 = Cells(d, 52).Value
Price5 = Cells(e, 53).Value
Price6 = Cells(f, 54).Value
Price7 = Cells(g, 55).Value
So if Price 3,4, and 5 are all € 5
And Price 6 and 7 are both € 1
Then "Largest3PriceGroup2" should be 15 within this iterination
For this I can write a very large code (in a way similar to what i did with group 1), but I am sure that there has to be a way more efficient method for this.
What I think needs to be done is to create an Array that contains the values of price 3 to 5 and then efficiently assigns the SUM of the top 3 values to "Largest3PriceGroup2"
Usually Google and your forum are my best friends for this, but I still haven't been able to figure this out.
Therefore I hope one of you is willing to help me out on my quest
All help greatly appreciated ofcourse!
I have a loop running through my code.
I will not post the entire code, but it goes through millions of combinations, created from 15 columns filled with prices.
Each combination consists of 15 values (one value from each column)
Within these columns there are groups.
For example the values from the first two columns can be considered group1,
and the values used from column 3 to 7 can be considered group2
First I had to find the largest value in each possible combination within group 2 - which was doable for me like this:
Code:
Largest1PriceGroup1 = Cells(a, 49).Value
If Cells(a, 49).Value < Cells(b, 50) Then
LargestPriceGroup1= Cells(b, 50).Value
End If
However, after this I need to SUM the largest 3 of 5 values in group 2
Price3 = Cells(c, 51).Value
Price4 = Cells(d, 52).Value
Price5 = Cells(e, 53).Value
Price6 = Cells(f, 54).Value
Price7 = Cells(g, 55).Value
So if Price 3,4, and 5 are all € 5
And Price 6 and 7 are both € 1
Then "Largest3PriceGroup2" should be 15 within this iterination
For this I can write a very large code (in a way similar to what i did with group 1), but I am sure that there has to be a way more efficient method for this.
What I think needs to be done is to create an Array that contains the values of price 3 to 5 and then efficiently assigns the SUM of the top 3 values to "Largest3PriceGroup2"
Usually Google and your forum are my best friends for this, but I still haven't been able to figure this out.
Therefore I hope one of you is willing to help me out on my quest
All help greatly appreciated ofcourse!
Last edited: