Extract Numbers and Text from Single Cell with Multiple Numbers & Text

JacksonTriggs

New Member
Joined
Nov 4, 2021
Messages
20
Office Version
  1. 365
Platform
  1. MacOS
Hi all!

Despite searching for similar posts, I have not found a solution to the following problem regarding a single cell with a very long string of multiple numbers and text.
Here is a part of it: 118 A&E 131 AMC 184 Animal Planet....

How can I extract this string into rows with two columns as follows please?

118A&E
131AMC
184Animal Planet

I tried Text to Columns with a space delimiter, but that ended up splitting "Animal" from "Planet" too, so no luck there.

Thanks in advance! Respect!
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
... with a very long string of multiple numbers and text.
Here is a part of it: 118 A&E 131 AMC 184 Animal Planet....

As long as the string format conforms to the example you posted, something like this will do it. The example assumes your single cell data is in cell A1
VBA Code:
Sub SplitToColumns()
    Dim I As Long, J As Long
    Dim S As String, CellData As String
    Dim SA As Variant
   
    CellData = Application.Trim(Range("A1").Value)
    'CellData = "118 A&E 131 AMC 184 Animal Planet"
   
    SA = Split(CellData, " ")
    J = 1
    For I = LBound(SA) To UBound(SA)
        If VBA.IsNumeric(SA(I)) Then
            S = ""
            J = J + 1
            Cells(J, 1) = SA(I)
        Else
            S = S & SA(I) & " "
            Cells(J, 2) = Trim(S)
        End If
    Next I
End Sub
 
Upvote 0
Solution
Wow, @rlv01, did you just whip up that fantastic and perfectly executing macro on the spot? I'm amazed either way. Thank you so very much! :)
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
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