Unit of measure in number format

falconeyes

New Member
Joined
Dec 7, 2009
Messages
4
I have a worksheet in which cell contains both numbers and texts. The cells have units of measurement attached to number and these UOM are included in number format.

For example, the cell has 2.0 kg. The format for the cell is custom and
reads #,##0.0" KG";-#,##0.0" KG";#,##0.0;@.

Kindly guide me as I want to extract the UOM from the values.


Regards

Ahmad
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
If the cells are all formatted
Code:
#,##0.0" KG";-#,##0.0" KG";#,##0.0;@
Why do you need to extract the UOM, it can only be "KG"
If your Data is in A2 down then you could try in B2 (I can't see why though)
Code:
=IF(ISNUMBER(A2),"Kg","")
However if the cells are individually formatted with different UOMs then you will need a UDF
In a standard Module
Code:
Function ExtractUOM(rng As Range) As String
    Dim strTemp As String
    If IsNumeric(rng) Then
        strTemp = WorksheetFunction.Substitute(rng.NumberFormat, Chr(34), "|", 2)
        strTemp = Trim(Mid(strTemp, InStr(1, strTemp, Chr(34)) + 1, InStr(1, strTemp, "|") - InStr(1, strTemp, Chr(34)) - 1))
    End If
    ExtractUOM = strTemp
End Function
Use in B2
Code:
=ExtractUOM(A2)
Drag/Fill Down
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,889
Messages
6,181,611
Members
453,056
Latest member
apmale77

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