Help with a unit convert table with formulas and multiple index/match criteria

StrawberryDreams

Board Regular
Joined
Mar 26, 2022
Messages
75
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
  3. Mobile
I've built a table that converts the value based on the Original Unit and the Converted to Unit. The New cell value relies on another table that has the multiple possibilities and results that are used to pull from using index match.

The Element table allows the user to select an Element and its Value. As it stands everything works but I don't know how to expand the Element table to do another conversion for another element without getting a spill error ( Convert Table would have to have each of the 9 possible formula results written for each possible Element Name). I could do that but would like to learn if there is a better more elegant way to do this even in VBA if that makes it easier ?

Basic data calculator test 9.9b.xlsm
ABCDEFGHIJK
1Original UnitElementAtomic WeightValencemmol/L = ppm / atomic weight
2mmol/LN141meq/L = ppm * Valence / Atomic Weight
3Convert to UnitCa302ppm = meq/L * Atomic Weight / Valence
4meq/L
5Convert Table
6Element ChoosenOriginal UnitConvert to UnitNew Value ResultConvert formulas for New Value Result
7Cappmppm120No conversion needed - Units match
8ElementValueNew ValueCappmmmol/L4mmol/L = Cell Value * Atomic weight
9Ca120240Cappmmeq/L8meq/L = (Cell Value * Valence) / Atomic Weight
10
11Cammol/Lmmol/L120No conversion needed - Units match
12Cammol/Lppm3600ppm = Cell Value * Atomic Weight
13Cammol/Lmeq/L240meq/L = Cell Value * Valence
14
15Cameq/Lmeq/L120No conversion needed - Units match
16Cameq/Lppm1800ppm = Cell Value * Atomic Weight / Valence
17Cameq/Lmmol/L60mmol/L = Cell Value / Valence
Sheet1
Cell Formulas
RangeFormula
C9C9=INDEX(Table26[New Value Result],MATCH(1,(Table26[Original Unit]=A2)*(Table26[Convert to Unit]=A4),0))
F7:F8,F15:F17,F11:F13F7=Table24[Element]
F9F9=Table24[@Element]
I7,I15,I11I7=Table24[Value]
I8I8=Table24[Value] / INDEX(Table25[Atomic Weight],MATCH(Table24[Element],Table25[Element],0))
I9I9=Table24[Value] * INDEX(Table25[Valence],MATCH(Table24[@Element],Table25[Element],0)) / (INDEX(Table25[Atomic Weight],MATCH(Table24[Element],Table25[Element],0)))
K11,K15K11=K7
I12I12=Table24[Value]* INDEX(Table25[Atomic Weight],MATCH(Table24[Element],Table25[Element],0))
I13I13=Table24[Value] * INDEX(Table25[Valence],MATCH(Table24[Element],Table25[Element],0))
I16I16=Table24[Value] * INDEX(Table25[Atomic Weight],MATCH(Table24[Element],Table25[Element],0)) / INDEX(Table25[Valence],MATCH(Table24[Element],Table25[Element],0))
I17I17=Table24[Value] / INDEX(Table25[Valence],MATCH(Table24[Element],Table25[Element],0))
Cells with Data Validation
CellAllowCriteria
A4:A5Listppm, mmol/L, meq/L
A2Listppm, mmol/L, meq/L
A9ListN,Ca


1715117299860.png
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
See if this works for you.
Book1
ABCDEFGHIJK
1Original UnitElementAtomic WeightValenceElementOriginalCovertValueNew Value
2ppmTotal N14.00671Cappmppm120120
3Convert to UnitNO3-14.00671Cappmmmol/L1004008
4meq/LNH414.00671Cappmmeq/L1206
5P30.9737621Cammol/Lmmol/L100100
6K39.09831Cammol/Lppm1204809
7S32.0652Pmmol/Lmeq/L100100
8Ca40.0782Cameq/Lmeq/L120120
9Mg24.3052Mgmeq/Lppm1001215
10Fe55.8452Cameq/Lmmol/L12060
11Mn54.9380442
12B10.8112
13Cu63.5462
14Zn65.382
15Mo95.951
16Cl35.4531
17Si28.08554
18Co58.9331951
19Na22.9897691
20Ni58.69341
Sheet13
Cell Formulas
RangeFormula
K2:K10K2=LET(w,XLOOKUP(G2,$C$2:$C$20,$D$2:$D$20),v,XLOOKUP(G2,$C$2:$C$20,$E$2:$E$20), oldval,J2, SWITCH(H2&I2,"ppmmmol/L",oldval*w,"ppmmeq/L",(oldval*v)/w,"mmol/Lppm",oldval*w,"mmol/Lmeq/L",oldval*v,"meq/Lppm",oldval*w/v,"meq/Lmmol/L",oldval/v,oldval))
Cool , will try it out . Looks like some of the manual conversion formulas are moved around and giving different results - but seems to be working. I'll delve into the switch part of your formula and see if i can rearrange the math to get the conversions. Cheers
 
Upvote 0
See if this works for you.
Book1
ABCDEFGHIJK
1Original UnitElementAtomic WeightValenceElementOriginalCovertValueNew Value
2ppmTotal N14.00671Cappmppm120120
3Convert to UnitNO3-14.00671Cappmmmol/L1004008
4meq/LNH414.00671Cappmmeq/L1206
5P30.9737621Cammol/Lmmol/L100100
6K39.09831Cammol/Lppm1204809
7S32.0652Pmmol/Lmeq/L100100
8Ca40.0782Cameq/Lmeq/L120120
9Mg24.3052Mgmeq/Lppm1001215
10Fe55.8452Cameq/Lmmol/L12060
11Mn54.9380442
12B10.8112
13Cu63.5462
14Zn65.382
15Mo95.951
16Cl35.4531
17Si28.08554
18Co58.9331951
19Na22.9897691
20Ni58.69341
Sheet13
Cell Formulas
RangeFormula
K2:K10K2=LET(w,XLOOKUP(G2,$C$2:$C$20,$D$2:$D$20),v,XLOOKUP(G2,$C$2:$C$20,$E$2:$E$20), oldval,J2, SWITCH(H2&I2,"ppmmmol/L",oldval*w,"ppmmeq/L",(oldval*v)/w,"mmol/Lppm",oldval*w,"mmol/Lmeq/L",oldval*v,"meq/Lppm",oldval*w/v,"meq/Lmmol/L",oldval/v,oldval))
it was just the first formula was a * instead of a /. All good now . I probably wrote the original formula incorrectly.

Much better then copying 9 possibilities of code into 170 rows in a table. thanks again!
 
Upvote 0
You stated "it was just the first formula was a * instead of a /. All good now

Please show your edits and comparison to expected results.
N.B.
I am not familiar with these conversion; I just thought the results should be logical. I completed minimal tests.
You can name the new function in Name Manager and show the parameters.

Draft
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,114
Messages
6,128,910
Members
449,478
Latest member
Davenil

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