Separate number from text

sean1541

New Member
Joined
Feb 14, 2023
Messages
31
Office Version
  1. 2016
Platform
  1. MacOS
Hi I want to separate the number from the text
using 2016 excel


Potatoes Prepared 162kg
Potatoes Prepared
162kg


Book1
ABCDE
1
2Potatoes Prepared 162kg
3Carrots Diced 80kg
4Bananas - box 92kg
5Spanish Onions - bag 10kg
6Lettuce 35 Heads
7Stir Fry Veg Mix - bag 25kg
8Mixed Peppers - box 1kg
9Mushrooms - carton 11kg
10Leeks - bag 5kg
11Tomatoes 20kg
12
13Turnips - Diced 80kg
14Potatoes Prepared 10kg
15Garlic Strings 1kg
16Stir Fry Veg Mix - bag 25kg
17Cauliflower 3 Heads
18Broccoli 6kg
19Coleslaw Mix 15kg
20
21
Inventory
 

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".
With Power Query
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Split Column by Character Transition" = Table.SplitColumn(#"Changed Type", "Column1", Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0".."9"}, c), {"0".."9"}), {"Column1.1", "Column1.2"})
in
    #"Split Column by Character Transition"

Book1
ABCD
3Column1Column1.1Column1.2
4Potatoes Prepared 162kgPotatoes Prepared 162kg
5Carrots Diced 80kgCarrots Diced 80kg
6Bananas - box 92kgBananas - box 92kg
7Spanish Onions - bag 10kgSpanish Onions - bag 10kg
8Lettuce 35 HeadsLettuce 35 Heads
9Stir Fry Veg Mix - bag 25kgStir Fry Veg Mix - bag 25kg
10Mixed Peppers - box 1kgMixed Peppers - box 1kg
11Mushrooms - carton 11kgMushrooms - carton 11kg
12Leeks - bag 5kgLeeks - bag 5kg
13Tomatoes 20kgTomatoes 20kg
14
15Turnips - Diced 80kgTurnips - Diced 80kg
16Potatoes Prepared 10kgPotatoes Prepared 10kg
17Garlic Strings 1kgGarlic Strings 1kg
18Stir Fry Veg Mix - bag 25kgStir Fry Veg Mix - bag 25kg
19Cauliflower 3 HeadsCauliflower 3 Heads
20Broccoli 6kgBroccoli 6kg
21Coleslaw Mix 15kgColeslaw Mix 15kg
Sheet1
 
Upvote 1
Hi
A VBA!!
VBA Code:
Sub test()
Dim a, m
Dim i&
a = Cells(2, 1).Resize(Cells(Rows.Count, 1).End(xlUp).Row).Resize(, 3)
With CreateObject("VBScript.RegExp")
        .Global = True
        .Pattern = "\d+.+"
        For i = 1 To UBound(a)
        If (Trim(a(i, 1))) <> "" Then
        Set m = .Execute(a(i, 1))
        a(i, 2) = m(0)
        a(i, 3) = Trim(Replace(a(i, 1), m(0), ""))
        End If
      Next
    End With
Cells(2, 1).Resize(UBound(a), UBound(a, 2)) = a
End Sub
 
Upvote 1
Or
VBA Code:
Sub test()
Dim a, m
Dim i&
a = Cells(2, 1).Resize(Cells(Rows.Count, 1).End(xlUp).Row).Resize(, 3)
With CreateObject("VBScript.RegExp")
        .Global = True
        .Pattern = "\d+.+"
        For i = 1 To UBound(a)
        If (Trim(a(i, 1))) <> "" Then
        Set m = .Execute(a(i, 1))
        a(i, 3) = m(0)
        a(i, 2) = Trim(Replace(a(i, 1), m(0), ""))
        End If
      Next
    End With
Cells(2, 1).Resize(UBound(a), UBound(a, 2)) = a
End Sub
 
Upvote 1
With Formulas?

23 03 04.xlsm
ABC
1
2Potatoes Prepared 162kgPotatoes Prepared162kg
3Carrots Diced 80kgCarrots Diced80kg
4Bananas - box 92kgBananas - box92kg
5Spanish Onions - bag 10kgSpanish Onions - bag10kg
6Lettuce 35 HeadsLettuce35 Heads
7Stir Fry Veg Mix - bag 25kgStir Fry Veg Mix - bag25kg
8Mixed Peppers - box 1kgMixed Peppers - box1kg
9Mushrooms - carton 11kgMushrooms - carton11kg
10Leeks - bag 5kgLeeks - bag5kg
11Tomatoes 20kgTomatoes20kg
12   
13Turnips - Diced 80kgTurnips - Diced80kg
14Potatoes Prepared 10kgPotatoes Prepared10kg
15Garlic Strings 1kgGarlic Strings1kg
16Stir Fry Veg Mix - bag 25kgStir Fry Veg Mix - bag25kg
17Cauliflower 3 HeadsCauliflower3 Heads
18Broccoli 6kgBroccoli6kg
19Coleslaw Mix 15kgColeslaw Mix15kg
Split
Cell Formulas
RangeFormula
B2:B19B2=TRIM(LEFT(A2,MIN(FIND({1,2,3,4,5,6,7,8,9,0},A2&1234567890))-1))
C2:C19C2=TRIM(REPLACE(A2,1,LEN(B2),""))
 
Upvote 1
Solution
With Formulas?

23 03 04.xlsm
ABC
1
2Potatoes Prepared 162kgPotatoes Prepared162kg
3Carrots Diced 80kgCarrots Diced80kg
4Bananas - box 92kgBananas - box92kg
5Spanish Onions - bag 10kgSpanish Onions - bag10kg
6Lettuce 35 HeadsLettuce35 Heads
7Stir Fry Veg Mix - bag 25kgStir Fry Veg Mix - bag25kg
8Mixed Peppers - box 1kgMixed Peppers - box1kg
9Mushrooms - carton 11kgMushrooms - carton11kg
10Leeks - bag 5kgLeeks - bag5kg
11Tomatoes 20kgTomatoes20kg
12   
13Turnips - Diced 80kgTurnips - Diced80kg
14Potatoes Prepared 10kgPotatoes Prepared10kg
15Garlic Strings 1kgGarlic Strings1kg
16Stir Fry Veg Mix - bag 25kgStir Fry Veg Mix - bag25kg
17Cauliflower 3 HeadsCauliflower3 Heads
18Broccoli 6kgBroccoli6kg
19Coleslaw Mix 15kgColeslaw Mix15kg
Split
Cell Formulas
RangeFormula
B2:B19B2=TRIM(LEFT(A2,MIN(FIND({1,2,3,4,5,6,7,8,9,0},A2&1234567890))-1))
C2:C19C2=TRIM(REPLACE(A2,1,LEN(B2),""))
Hi is there a way to extract bag, box etc into a separate column.
 
Upvote 0
This should do

VBA Code:
Sub jec()
 Dim ar, i As Long
 ar = Range("A2").CurrentRegion.Resize(, 3)
 With CreateObject("VBScript.RegExp")
   For i = 1 To UBound(ar)
     .Global = True
     .Pattern = "(?:.*?)(\d+)(.+)(?=$)"
      ar(i, 2) = .Replace(ar(i, 1), "$1")
      ar(i, 3) = Trim(.Replace(ar(i, 1), "$2"))
   Next
   Range("A2").CurrentRegion.Resize(, 3) = ar
 End With
End Sub
 
Upvote 0
This should do

VBA Code:
Sub jec()
 Dim ar, i As Long
 ar = Range("A2").CurrentRegion.Resize(, 3)
 With CreateObject("VBScript.RegExp")
   For i = 1 To UBound(ar)
     .Global = True
     .Pattern = "(?:.*?)(\d+)(.+)(?=$)"
      ar(i, 2) = .Replace(ar(i, 1), "$1")
      ar(i, 3) = Trim(.Replace(ar(i, 1), "$2"))
   Next
   Range("A2").CurrentRegion.Resize(, 3) = ar
 End With
End Sub
With CreateObject("VBScript.RegExp")

this is coming as error
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,116
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