How to synchronize two tables?

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,687
Office Version
  1. 365
Platform
  1. Windows
I am working on a project to calculate product ratings. It's a fairly complicated process so most of the calculations will be done in a macro. The project requires two "tables" that must have their columns aligned.
I am looking for the best way to keep two "tables" in sync -- or to be able to determine if they are out of alignment so it can return an error.

The illustration below is an example of 5 hypothetical electric vehicles with 4 properties: Price, Range, and two different external ratings (one on a 1-5 scale, the other on a 0-10 scale). The last 5 columns will not be part of the worksheet table. That work will be done in the macro. I have included them here for illustration purposes. The macro needs to access both the data table itself as well as the control data in the rows above the table. This example shows 2 control rows. The values in the Order row tell the macro whether these values are Hi-Lo (higher values are better) or Lo-Hi (lower values are better). The values in the Weight row tell the macro how much relative weight to assign to each property. In this example, Price is the only Lo-Hi property. The macro will use the property data to calculate z scores for each property, apply the weights, then convert the result to a 0-100 scale.

If I assign the weights as shown, I get the ratings shown.

1711942346480.png


I will need to add columns to the data table. When I do, I'll need to add synchronized columns to the control rows above the table. In my current implementation, I pass just the data table to the macro. It uses the address and dimensions of the table to access the control rows above. It then checks that the "headers" of the control rows match those of the data table. I have replicated the table headers in the row above the control rows so the macro can check that they are aligned. This works pretty well, but is there a better way?

I tried making the control rows into a table, too. It was simpler for the macro, but caused all kinds of problems with adding columns.

Here's the mini-sheet:

Weighted Ratings Demo.xlsx
BCDEFGHIJKLM
3Control Rows
4ProductRatingPriceRangeRtg1Rtg2
5OrderLo-HiHi-LoHi-LoHi-Lo
6Weights2.003.001.001.50Calculations Done in the Macro
7Max4.599
8Date TableMin-6.455
9ProductRatingPriceRangeRtg1Rtg2--Z PriceZ RangeZ Rtg1Z Rtg2Z Sum
10D100$80,000450 mi4.79.5---1.43+0.80+1.14+2.62+4.60
11E88$51,000460 mi4.68.1--+0.17+1.02+0.62-0.49+3.29
12A75$32,000420 mi4.58.0--+1.21+0.13+0.10-0.71+1.87
13B29$62,000390 mi4.48.2---0.44-0.53-0.42-0.27-3.30
14C0$45,000350 mi4.27.8--+0.50-1.42-1.46-1.15-6.45
15Std Dev$18,12545 mi0.20.7--1.00+1.00+1.00+1.50+4.69
16Mean $54,000414 mi4.58.3--0.000.000.000.000.00
MrExcel
Cell Formulas
RangeFormula
B4B4=TblTest[[#Headers],[Product]]
C4C4=TblTest[[#Headers],[Rating]]
D4D4=TblTest[[#Headers],[Price]]
E4E4=TblTest[[#Headers],[Range]]
F4F4=TblTest[[#Headers],[Rtg1]]
G4G4=TblTest[[#Headers],[Rtg2]]
M7M7=MAX(TblTest[Z Sum])
M8M8=MIN(TblTest[Z Sum])
I10:I14I10=([@Price]-D$16)/TblTest[[#Totals],[Price]] * ((D$5="Hi-Lo")*2-1)
J10:J14J10=([@Range]-E$16)/TblTest[[#Totals],[Range]] * ((E$5="Hi-Lo")*2-1)
K10:K14K10=F$6 * ([@Rtg1]-F$16)/TblTest[[#Totals],[Rtg1]] * ((F$5="Hi-Lo")*2-1)
L10:L14L10=G$6 * ([@Rtg2]-G$16)/TblTest[[#Totals],[Rtg2]] * ((G$5="Hi-Lo")*2-1)
M10:M14M10=D$6*[@[Z Price]] + E$6*[@[Z Range]] + F$6*[@[Z Rtg1]] + G$6*[@[Z Rtg2]]
I15I15=SUBTOTAL(107,[Z Price])
J15J15=SUBTOTAL(107,[Z Range])
K15K15=SUBTOTAL(107,[Z Rtg1])
L15L15=SUBTOTAL(107,[Z Rtg2])
M15M15=SUBTOTAL(107,[Z Sum])
I16I16=AVERAGE(TblTest[Z Price])
J16J16=AVERAGE(TblTest[Z Range])
K16K16=AVERAGE(TblTest[Z Rtg1])
L16L16=AVERAGE(TblTest[Z Rtg2])
M16M16=AVERAGE(TblTest[Z Sum])
C10:C14C10=100 * ([@[Z Sum]]-M$8) / (M$7-M$8)
D15D15=SUBTOTAL(107,[Price])
E15E15=SUBTOTAL(107,[Range])
F15F15=SUBTOTAL(107,[Rtg1])
G15G15=SUBTOTAL(107,[Rtg2])
D16D16=AVERAGE(TblTest[Price])
E16E16=AVERAGE(TblTest[Range])
F16F16=AVERAGE(TblTest[Rtg1])
G16G16=AVERAGE(TblTest[Rtg2])
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,223,782
Messages
6,174,520
Members
452,569
Latest member
Ron1970

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