Formula to pull number before particular charecters ( KG and L

Ncleveng

New Member
Joined
Jan 17, 2019
Messages
5
Hello,

I need a formula t pull the Number and Charters for example:

"SSRG POLYL P400E HCG DRST210kg"

I want only the 210KG pulled or if its LB 210LB



:)


Thank you!
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hi,

Is the kg or lb Always at the End of the Text string ?
 
Upvote 0
if you are able to use PowerQuery not formula try

Column1Result
SSRG POLYL P400E HCG DRST210kg210kg
VVAA ROLL Z9921 KL22 TREE400LB400LB
ABC DEFG 333ZZ OKM11 PRESWERK9912KG9912KG

Code:
[SIZE=1]let
    Source = Excel.CurrentWorkbook(){[Name="Table4"]}[Content],
    #"Extracted Text After Delimiter" = Table.TransformColumns(Source, {{"Column1", each Text.AfterDelimiter(_, " ", {0, RelativePosition.FromEnd}), type text}}),
    #"Inserted Last Characters" = Table.AddColumn(#"Extracted Text After Delimiter", "Last Characters", each Text.End([Column1], 2), type text),
    #"Added Custom" = Table.AddColumn(#"Inserted Last Characters", "Custom", each Text.Trim([Column1],{"a".."z","A".."Z"})),
    #"Merged Columns" = Table.CombineColumns(#"Added Custom",{"Custom", "Last Characters"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Result"),
    #"Removed Other Columns" = Table.SelectColumns(#"Merged Columns",{"Result"})
in
    #"Removed Other Columns"[/SIZE]
 
Last edited:
Upvote 0
99% of the time so I'd be happy with that yes!

Perhaps if you show more samples instead of just 1, we may be able to handle the rest...

Try this:


Book1
AB
1SSRG POLYL P400E HCG DRST210kg210kg
2SSRG POLYL P400E HCG DRST1045lb1045lb
Sheet470
Cell Formulas
RangeFormula
B1=MID(RIGHT(SUBSTITUTE(A1," ",REPT(" ",99)),99),LOOKUP(118,MIN(FIND({0,1,2,3,4}+{0;5},RIGHT(SUBSTITUTE(A1," ",REPT(" ",99)),99)&1/17))),99)
 
Upvote 0
or this,
no matter where is the string with kg or lb in the whole string
condition: kg or lb must have space on the end

Column1Result
SSRG POLYL P400E HCG DRST210kg210KG
VVAA ROLL Z9921 KL22 TREE400LB400LB
ABC DEFG 333ZZ OKM11 PRESWERK9912KG9912KG
CCC 234KDF qwe345kg WTC WHO NSA500345KG
660LB PORKY 3WIJE O45ONZ BU5HAHA660LB
GUI99kg StOng 341GG ARMEE HH3400W99KG

Code:
[SIZE=1]let
    #"Uppercased Text" = Table.TransformColumns(Excel.CurrentWorkbook(){[Name="Table4"]}[Content],{{"Column1", Text.Upper, type text}}),
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Uppercased Text", {{"Column1", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Column1"),
    #"Added Conditional Column" = Table.AddColumn(#"Split Column by Delimiter", "Custom", each if Text.Contains([Column1], "KG") then [Column1] else if Text.Contains([Column1], "LB") then [Column1] else null),
    #"Merged Columns" = Table.CombineColumns(Table.AddColumn(Table.AddColumn(Table.SelectRows(#"Added Conditional Column", each ([Custom] <> null)), "Last Characters", each Text.End([Custom], 2), type text), "Custom.1", each Text.Trim([Custom],{"a".."z","A".."Z"})),{"Custom.1", "Last Characters"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Result"),
    #"Removed Other Columns" = Table.SelectColumns(#"Merged Columns",{"Result"})
in
    #"Removed Other Columns"[/SIZE]
 
Last edited:
Upvote 0
This worked great! How possible would it be to convert any Lb amounts to KG? If that would be possible I wouldn't need the unit at the end. If its a pain, no issue.
 
Upvote 0
u didn't answer about PowerQuery and to whom u r talkin'
so just for fun here is:

Column1Result
SSRG POLYL P400E HCG DRST210kg
210​
VVAA ROLL Z9921 KL22 TREE400LB
181.44​
ABC DEFG 333ZZ OKM11 PRESWERK9912KG
9912​
CCC 234KDF qwe345kg WTC WHO NSA500
345​
660LB PORKY 3WIJE O45ONZ BU5HAHA
299.37​
GUI99kg StOng 341GG ARMEE HH3400W
99​

Code:
[SIZE=1]let
    #"Uppercased Text" = Table.TransformColumns(Excel.CurrentWorkbook(){[Name="Table4"]}[Content],{{"Column1", Text.Upper, type text}}),
    ExtractNumber = Table.TransformColumnTypes(Table.AddColumn(Table.SelectRows(Table.AddColumn(Table.ExpandListColumn(Table.TransformColumns(#"Uppercased Text", {{"Column1", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Column1"), "Custom", each if Text.Contains([Column1], "KG") then [Column1] else if Text.Contains([Column1], "LB") then [Column1] else null), each ([Custom] <> null)), "Custom.1", each Text.Trim([Custom],{"A".."Z"})),{{"Custom.1", type number}}),
    Convert2KG = Table.SelectColumns(Table.TransformColumns(Table.TransformColumnTypes(Table.AddColumn(ExtractNumber, "Result", each if Text.Contains([Custom], "LB") then [Custom.1]*0.453592 else [Custom.1]),{{"Result", type number}}),{{"Result", each Number.Round(_, 2), type number}}),{"Result"})
in
    Convert2KG[/SIZE]

result is converted from LB 2 KG (where 1 LB = 0.453592 KG) and rounded to 2 decimals
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,198
Members
449,072
Latest member
DW Draft

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