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

StrawberryDreams

Board Regular
Joined
Mar 26, 2022
Messages
79
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

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hello S...

What about a lambda?

Mappe7
ABCDEFGHI
1Original UnitElementAtomic WeightValenceElementValueNew Value
2mmol/LN143Ca120240
3Convert to UnitCa302N1442
4meq/L
5
Tabelle1
Cell Formulas
RangeFormula
I2:I3I2=convert_waterchemistry($A$2,$A$4,[@Element],[@Value])


Hmm... XL2BB didn't insert the named ranges.

Name: convert_waterchemistry
Formula:
Excel Formula:
=LAMBDA(from_unit,to_unit,element,value,
LET(
atomic_weight,XLOOKUP(element,Table25[Element],Table25[Atomic Weight]),
valence,XLOOKUP(element,Table25[Element],Table25[Valence],
ppm_mmol,value*atomic_weight,
ppm_meq,value*valence/atomic_weight,
mmol_ppm,value*atomic_weight,
mmol_meq,value*valence,
meq_ppm,value*atomic_weight/valence,
meq_mmol,value/valence,
i,MATCH(from_unit&"_"&to_unit,{"ppm_mmol/L";"ppm_meq/L";"mmol/L_ppm";"mmol/L_meq/L";"meq/L_ppm";"meq/L_mmol/L"},0),
new_value,CHOOSE(i,ppm_mmol,ppm_meq,mmol_ppm,mmol_meq,meq_ppm,meq_mmol), new_value))
 
Upvote 0
Hello S...

What about a lambda?

Mappe7
ABCDEFGHI
1Original UnitElementAtomic WeightValenceElementValueNew Value
2mmol/LN143Ca120240
3Convert to UnitCa302N1442
4meq/L
5
Tabelle1
Cell Formulas
RangeFormula
I2:I3I2=convert_waterchemistry($A$2,$A$4,[@Element],[@Value])


Hmm... XL2BB didn't insert the named ranges.

Name: convert_waterchemistry
Formula:
Excel Formula:
=LAMBDA(from_unit,to_unit,element,value,
LET(
atomic_weight,XLOOKUP(element,Table25[Element],Table25[Atomic Weight]),
valence,XLOOKUP(element,Table25[Element],Table25[Valence],
ppm_mmol,value*atomic_weight,
ppm_meq,value*valence/atomic_weight,
mmol_ppm,value*atomic_weight,
mmol_meq,value*valence,
meq_ppm,value*atomic_weight/valence,
meq_mmol,value/valence,
i,MATCH(from_unit&"_"&to_unit,{"ppm_mmol/L";"ppm_meq/L";"mmol/L_ppm";"mmol/L_meq/L";"meq/L_ppm";"meq/L_mmol/L"},0),
new_value,CHOOSE(i,ppm_mmol,ppm_meq,mmol_ppm,mmol_meq,meq_ppm,meq_mmol), new_value))
I had found a mistake in my original index match formulas not referencing the proper table... so Im rewriting it now and can resubmit when fully fixed.
 
Upvote 0
Hello S...

What about a lambda?

Mappe7
ABCDEFGHI
1Original UnitElementAtomic WeightValenceElementValueNew Value
2mmol/LN143Ca120240
3Convert to UnitCa302N1442
4meq/L
5
Tabelle1
Cell Formulas
RangeFormula
I2:I3I2=convert_waterchemistry($A$2,$A$4,[@Element],[@Value])


Hmm... XL2BB didn't insert the named ranges.

Name: convert_waterchemistry
Formula:
Excel Formula:
=LAMBDA(from_unit,to_unit,element,value,
LET(
atomic_weight,XLOOKUP(element,Table25[Element],Table25[Atomic Weight]),
valence,XLOOKUP(element,Table25[Element],Table25[Valence],
ppm_mmol,value*atomic_weight,
ppm_meq,value*valence/atomic_weight,
mmol_ppm,value*atomic_weight,
mmol_meq,value*valence,
meq_ppm,value*atomic_weight/valence,
meq_mmol,value/valence,
i,MATCH(from_unit&"_"&to_unit,{"ppm_mmol/L";"ppm_meq/L";"mmol/L_ppm";"mmol/L_meq/L";"meq/L_ppm";"meq/L_mmol/L"},0),
new_value,CHOOSE(i,ppm_mmol,ppm_meq,mmol_ppm,mmol_meq,meq_ppm,meq_mmol), new_value))
this looks interesting... trying to implement it and I'm guessing I have to create named ranges and assign them to each table column ref.

Do I insert this large lambda formula in the name manager refers to location box ?
 
Upvote 0
So I named the ranges ; element, atomic_weight, valence, and value. Then I created another name called water_chemistry and entered the Lambda formula you made and got an error saying - " You've entered too many arguments. for this function." I must be missing something else I need to name ?
 
Upvote 0
You only need the defined name "convert_waterchemistry". All the other names are set in LAMBDA() or LET().
 
Upvote 0
I had found a mistake in my original index match formulas not referencing the proper table... so Im rewriting it now and can resubmit when fully fixed.

You only need the defined name "convert_waterchemistry". All the other names are set in LAMBDA() or LET().
I must be missing something or not entering it properly, or maybe being on a mac has limits ?

still getting the error when trying to enter in name manager.

1715143866726.png
 
Upvote 0
I deleted all the previous named ranges and only tried to use the convert_waterchemistry..... and still.

Basic data calculator test 9.9bc.xlsm
ABCDEFGHI
1Original UnitElementAtomic WeightValenceElementValueNew Value
2ppmTotal N14.00671P120#NAME?
3Convert to UnitNO3-14.00671Ca100#NAME?
4meq/LNH414.00671
5P30.9737621=LAMBDA(from_unit,to_unit,element,value, LET( atomic_weight,XLOOKUP(element,Table25[Element],Table25[Atomic Weight]), valence,XLOOKUP(element,Table25[Element],Table25[Valence], ppm_mmol,value*atomic_weight, ppm_meq,value*valence/atomic_weight, mmol_ppm,value*atomic_weight, mmol_meq,value*valence, meq_ppm,value*atomic_weight/valence, meq_mmol,value/valence, i,MATCH(from_unit&"_"&to_unit,{"ppm_mmol/L";"ppm_meq/L";"mmol/L_ppm";"mmol/L_meq/L";"meq/L_ppm";"meq/L_mmol/L"},0), new_value,CHOOSE(i,ppm_mmol,ppm_meq,mmol_ppm,mmol_meq,meq_ppm,meq_mmol), new_value))
6K39.09831
7S32.0652
8Ca40.0782
9Mg24.3052
10Fe55.8452
11Mn54.9380442
12B10.8112
13Cu63.5462
14Zn65.382
15Mo95.951
16Cl35.4531
17Si28.08554
18Co58.9331951
19Na22.9897691
20Ni58.69341
ppm to mmols (2)
Cell Formulas
RangeFormula
I2:I3I2=convert_waterchemistry($A$2,$A$4,[@Element],[@Value])
Cells with Data Validation
CellAllowCriteria
A2Listppm, mmol/L, meq/L
A4Listppm, mmol/L, meq/L
 
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))
 
Upvote 1
Solution

Forum statistics

Threads
1,224,811
Messages
6,181,082
Members
453,021
Latest member
Justyna P

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