What am I missing?

nilaco

New Member
Joined
Dec 17, 2019
Messages
13
Office Version
  1. 365
Platform
  1. Windows
I created this formula to convert all the values to mm whether they're listed as "imperial", "metric", "cm" or "inch" in column L. It works pretty well, but if the value is already listed as "mm", the formula adds an extra "0" to the end of the number (see row 9).

The formula I've used in columns P,Q & R is:

=IFERROR((IF(OR(L2="imperial",L2="inch"),(ROUNDUP(CONVERT(I2,"in","mm"),0)),(CONVERT(I2,"cm","mm")))),"")

1577796518197.png
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
The formula I've used in columns P,Q & R is:

=IFERROR((IF(OR(L2="imperial",L2="inch"),(ROUNDUP(CONVERT(I2,"in","mm"),0)),(CONVERT(I2,"cm","mm")))),"")
What are you expecting CONVERT(I2,"cm","mm") to do?
Converting 760cm to mm will multiply by 10.
 
Upvote 0
I see what you mean. Essentially what I need the formula to do is convert all the values to "mm" whether they're listed as "inch", "imperial", "cm", "metric" or "mm". I guess I need to insert an extra bit saying that if I2 is listed as "mm" then it should remain the same, but i'm not sure how I can work that into the formula.
 
Upvote 0
Where i'm stuck is that IF statements are based on whether whats written is true or false, but what I need I guess what I want to write is:

IF L2 = "imperial" or "inch", then convert inch to mm (and round up to the nearest whole mm)
IF L2 = "metric" or "cm", then convert cm to mm (and round up to the nearest whole mm)
IF L2 = "mm", then don't change a thing
then if the cell is blank or contains "-", then the cell should remain blank
 
Upvote 0
Sorry ignore that last post, i deleted part of a sentence by accident!!

Where i'm stuck is that IF statements are based on whether whats written is true or false, but I need it to be based on three possible outcomes. I guess what I want to write is:

IF L2 = "imperial" or "inch", then convert inch to mm (and round up to the nearest whole mm)
IF L2 = "metric" or "cm", then convert cm to mm (and round up to the nearest whole mm)
IF L2 = "mm", then don't change a thing
then if the cell is blank or contains "-", then the cell should remain blank
 
Upvote 0
I think that this should do it, I've tried it with a couple of values for each of the different descriptions in your list.

=IFERROR(ROUNDUP(CONVERT(I2,SUBSTITUTE(SUBSTITUTE(LEFT(L2,2),"Im","In"),"Me","cm"),"mm"),0),"")

You could do it with more IF's and OR's, but as you've found, that tends to start getting a bit messy.
 
Upvote 0
Thank you! Would you mind explaining how this formula works if you have the time?
 
Upvote 0
Hmm I've just applied it to the spreadsheet and only works for "cm" "inch" and "mm", but changes it to a blank cell for "imperial" and "metric"...
 
Upvote 0
I had never paid attention to the fact that SUBSTITUTE is case sensitive (until now).

A slight change and all appears to work well.
Book1
IJKLPQR
229.244.519.1cm292445191
358.471.6metric584716 
41823.532.5imperial458597826
5913.514.3inch229343364
6760925645mm760925645
Sheet2
Cell Formulas
RangeFormula
P2:R6P2=IF(ISNUMBER(I2),ROUNDUP(CONVERT(I2,SUBSTITUTE(SUBSTITUTE(LEFT(LOWER($L2),2),"im","in"),"me","cm"),"mm"),0),"")


The formula works by taking the first 2 (LEFT,$L2,2) characters of the unit of measurement, then SUBSTITUTING them with a valid unit in the case of (me)tric or (im)perial which are change to (cm) and (in) respectively.
This then gives a valid measurement unit to be converted, either 'in' for inch or imperial, 'cm' for cm or metric and mm remains unchanged.
I also noticed that you mentioned empty cells earlier, so I've changed the formula slightly to allow for that. An empty cell wouldn't cause an error so the original method would have given a 0 result in such cases.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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