JenniferMurphy
Well-known Member
- Joined
- Jul 23, 2011
- Messages
- 2,687
- Office Version
- 365
- Platform
- Windows
I am developing a weighted rating algorithm that I would like to implement in an Excel UDF or macro. It would operate on a sheet like the one below. Each row represents some product I am considering buying. Each column refers to an attribute (property) of that product that I care about. The columns with yellow cells above the table contain properties that are to be included in the rating. The rest are informational only and are not included in the rating.
The yellow cells are in 3 rows: Best, Worst, and Weight. The Best row contains the best value for that property. The Worst contain the worst. The Weight row contains the relative weight to be given to each property in the rating system. These values cannot be calculated by the code. These examples are all Max & Min, but they could be reversed or constants.
The rating code needs access to all of the yellow cells and all of the corresponding cells in each of the table rows in those columns. The code will compare the values in each row against the corresponding Best and Worst values, apply the weighting factor, and return the result to the corresponding cell in the Rating column.
If it's a UDF, the call would be like the examples shown in the Rating column (C). It will need to access each of the values in that row that are to be rated plus all of the cells in yellow and return the result to the calling cell.
If it's a macro, I would call it from a Button control. It will also need to access all of the cells in yellow plus all of the corresponding cells in all of the rows and return the values to all of the cells in the Rating column.
Either way, I want the calls to be independent of the number and position of the cells in yellow. That is, if I add another column of attributes whether it is to be included in the ratings or not, the calls won't have to change. The code will scan the sheet and identify the relevant cells to act on. It probably makes more sense to make it a macro so the sheet scan only has to be done once.
The yellow cells are in 3 rows: Best, Worst, and Weight. The Best row contains the best value for that property. The Worst contain the worst. The Weight row contains the relative weight to be given to each property in the rating system. These values cannot be calculated by the code. These examples are all Max & Min, but they could be reversed or constants.
The rating code needs access to all of the yellow cells and all of the corresponding cells in each of the table rows in those columns. The code will compare the values in each row against the corresponding Best and Worst values, apply the weighting factor, and return the result to the corresponding cell in the Rating column.
If it's a UDF, the call would be like the examples shown in the Rating column (C). It will need to access each of the values in that row that are to be rated plus all of the cells in yellow and return the result to the calling cell.
If it's a macro, I would call it from a Button control. It will also need to access all of the cells in yellow plus all of the corresponding cells in all of the rows and return the values to all of the cells in the Rating column.
Either way, I want the calls to be independent of the number and position of the cells in yellow. That is, if I add another column of attributes whether it is to be included in the ratings or not, the calls won't have to change. The code will scan the sheet and identify the relevant cells to act on. It probably makes more sense to make it a macro so the sheet scan only has to be done once.
Test 20220320.xlsx | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
B | C | D | E | F | G | H | I | J | K | |||
4 | Best | $12.99 | 12 mo | 20.00oz | 7.68" | 3.00" | ||||||
5 | Worst | $17.97 | 6 mo | 12.00oz | 6.30" | 2.50" | ||||||
6 | Weights | 2 | 1 | 4 | 2 | 2 | ||||||
7 | Brand | Rating | Price | Colors | Material | Warranty | Capacity | Height | Width | Comments | ||
8 | Brand A | =WtdRtd(???) | $17.97 | 6 | Glass | 6 mo | 12.00oz | 7.50" | 2.50" | |||
9 | Brand B | =WtdRtd(???) | $13.99 | 1 | Plastic | 9 mo | 16.00oz | 7.68" | 3.00" | |||
10 | Brand C | =WtdRtd(???) | $13.99 | 1 | Metal | 6 mo | 12.00oz | 6.30" | 2.90" | |||
11 | Brand D | =WtdRtd(???) | $12.99 | 3 | Metal | 12 mo | 20.00oz | 7.48" | 2.95" | |||
12 | Brand E | =WtdRtd(???) | $14.99 | 8 | Metal | 6 mo | 14.00oz | 7.20" | 2.83" | |||
Wtd Rtg |
Cell Formulas | ||
---|---|---|
Range | Formula | |
G4 | G4 | =MAX(WtdRtg[Warranty]) |
H4 | H4 | =MAX(WtdRtg[Capacity]) |
I4 | I4 | =MAX(WtdRtg[Height]) |
J4 | J4 | =MAX(WtdRtg[Width]) |
G5 | G5 | =MIN(WtdRtg[Warranty]) |
H5 | H5 | =MIN(WtdRtg[Capacity]) |
I5 | I5 | =MIN(WtdRtg[Height]) |
J5 | J5 | =MIN(WtdRtg[Width]) |
D4 | D4 | =MIN(WtdRtg[Price]) |
D5 | D5 | =MAX(WtdRtg[Price]) |