Choosing top scoring row (with complex logic/rules)

z3115

Board Regular
Joined
Nov 1, 2013
Messages
71
I have a set of data with different groups ("colors"). For each group (color), there are questions that apply to "categories" ("A", "B", "C", etc.). Each has a numerical score. I need to pick the highest scoring question for each category, for each group (color).



Example: Group "Blue" has 2 questions that apply to category "A". One has a score of 4, the other has a score of 2. The question with a score of 4 is the one that should be used.



This is simple enough, but there is an additional rule that makes everything more complicated: Some questions apply to multiple categories, but these questions can only be used for 1 category (or not used at all).



Because of this rule, there are several scenarios that come up, and as a result certain logic that needs to be applied:




  1. If a question applies to multiple categories and one of those categories has no other questions that apply to it, the question should be used for that category [Ex: if question 1 applies to categories A & B, and there are no other questions that apply to category A, question 1 should apply to category A. If neither category A nor category B have any other questions that apply to it, question 1 can be applied to either (but not both). It doesn't matter which one it's applied to.]
  2. If a question applies to multiple categories and each of those categories have other questions that apply to that category, the question that applies to multiple categories should be applied to lowest scoring category [Ex: "Question 4" applies to categories B & C and has a score of 7; "question 6" only applies to category B and has a score of 3. "Question 11" only applies to category C and has a score of 5. Since "question 6" scores worse than "question 11", "question 4" should be applied to category B. Note that if "question 4" had a score of 3 or lower, it would not be applied to either category


Is there any sort of formula or VBA code that can do anything like this?



Thank you all!




Example (the last column is the one I'm trying to automate):
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Color[/TD]
[TD]Question[/TD]
[TD]Categories it can be used for[/TD]
[TD]Score[/TD]
[TD]Category to apply it to[/TD]
[/TR]
[TR]
[TD]Red[/TD]
[TD]blah blah[/TD]
[TD]A[/TD]
[TD]4[/TD]
[TD]Don't Use[/TD]
[/TR]
[TR]
[TD]Red[/TD]
[TD]xyz[/TD]
[TD]A;B[/TD]
[TD]5[/TD]
[TD]A[/TD]
[/TR]
[TR]
[TD]Red[/TD]
[TD]gibberish[/TD]
[TD]C[/TD]
[TD]4[/TD]
[TD]C[/TD]
[/TR]
[TR]
[TD]Red[/TD]
[TD]hello[/TD]
[TD]C;D[/TD]
[TD]5[/TD]
[TD]D[/TD]
[/TR]
[TR]
[TD]Red[/TD]
[TD]lol[/TD]
[TD]B[/TD]
[TD]6[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]Blue[/TD]
[TD]ggdfklj[/TD]
[TD]A[/TD]
[TD]4[/TD]
[TD]A[/TD]
[/TR]
[TR]
[TD]Blue[/TD]
[TD]blah blah[/TD]
[TD]B[/TD]
[TD]6[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]Blue[/TD]
[TD]xyz[/TD]
[TD]C[/TD]
[TD]4[/TD]
[TD]C[/TD]
[/TR]
[TR]
[TD]Blue[/TD]
[TD]gibberish[/TD]
[TD]B;C[/TD]
[TD]3[/TD]
[TD]Don't Use[/TD]
[/TR]
[TR]
[TD]Blue[/TD]
[TD]hello[/TD]
[TD]D[/TD]
[TD]1[/TD]
[TD]D[/TD]
[/TR]
[TR]
[TD]Green[/TD]
[TD]ssasas[/TD]
[TD]A:B[/TD]
[TD]6[/TD]
[TD]A[/TD]
[/TR]
[TR]
[TD]Green[/TD]
[TD]sdsdff[/TD]
[TD]B[/TD]
[TD]4[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]Green[/TD]
[TD]fffrrd[/TD]
[TD]C[/TD]
[TD]4[/TD]
[TD]Don't Use[/TD]
[/TR]
[TR]
[TD]Green[/TD]
[TD]blah[/TD]
[TD]D[/TD]
[TD]6[/TD]
[TD]D[/TD]
[/TR]
[TR]
[TD]Green[/TD]
[TD]brrrr[/TD]
[TD]C;D[/TD]
[TD]8[/TD]
[TD]C[/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited:

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,223,889
Messages
6,175,224
Members
452,620
Latest member
dsubash

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