Unit conversions

newbieexcel24

New Member
Joined
Mar 14, 2024
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hello all I'm trying to have my spreadsheet automatically convert units:

=IF(ISBLANK(D8),"",IF(ISBLANK(E8),IF(RIGHT(D8,2)="ml",VALUE(LEFT(D8,LEN(D8)-2)),IF(RIGHT(D8,1)="L",VALUE(LEFT(D8,LEN(D8)-1))*1000,IF(RIGHT(D8,2)="kg",VALUE(LEFT(D8,LEN(D8)-2))*1000,IF(RIGHT(D8,1)="g",VALUE(LEFT(D8,LEN(D8)-1)),D8)))),E8*IF(RIGHT(D8,2)="ml",VALUE(LEFT(D8,LEN(D8)-2)),IF(RIGHT(D8,1)="L",VALUE(LEFT(D8,LEN(D8)-1))*1000,IF(RIGHT(D8,2)="kg",VALUE(LEFT(D8,LEN(D8)-2))*1000,IF(RIGHT(D8,1)="g",VALUE(LEFT(D8,LEN(D8)-1)),D8))))))

where E8 is the number of containers.

=IF(ISBLANK(D10),"",IF(ISBLANK(E10),IF(RIGHT(D10,2)="mg",VALUE(LEFT(D10,LEN(D10)-2))/1000),E10*IF(RIGHT(D10,2)="mg",VALUE(LEFT(D10,LEN(D10)-2))/1000)))

However the first formula doesn't work when I try to incorporate the mg conversion, it gives a value error- I think it's to do with the fact I've already have ml conversion as it had worked when I replaced the ml conversion with the mg conversion, they just don't seem to work side by side?

Thanks in advance!
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
You will need to check for mg before you check for g.
 
Upvote 0
You seem to be repeating some checks in that formula.
For example, I see this twice
IF(RIGHT(D8,1)="g",VALUE(LEFT(D8,LEN(D8)-1)),D8)

Can you give some realistic samples of what you are trying to do and expected results. Maybe we can simplify the formula.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0
automatically convert units:
Assuming that you are converting all volumes to "ml" and all masses to "g", what about this shorter option instead?

24 11 16.xlsm
DEF
7DataContainersResult
8125ml1125
9125L125000
10125g7875
11125kg1125000
121250MG56.25
132.45kg2450
Convert
Cell Formulas
RangeFormula
F8:F13F8=LET(u,LOWER(TAKE(TEXTSPLIT(D8,SEQUENCE(10)-1),,-1)),CONVERT(LEFT(D8,SEARCH(u,D8)-1),u,IF(RIGHT(D8,1)="L","ml","g")))*MAX(E8,1)


.. or if there is, or could be, a space between the number and the units, add a TRIM function

24 11 16.xlsm
DEF
7DataContainersResult
8125 ml1125
9125 L125000
10125g7875
11125kg1125000
121250 MG56.25
132.45kg2450
Convert (2)
Cell Formulas
RangeFormula
F8:F13F8=LET(u,TRIM(LOWER(TAKE(TEXTSPLIT(D8,SEQUENCE(10)-1),,-1))),CONVERT(LEFT(D8,SEARCH(u,D8)-1),u,IF(RIGHT(D8,1)="L","ml","g")))*MAX(E8,1)
 
Upvote 0

Forum statistics

Threads
1,224,821
Messages
6,181,163
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