Trying to extract variable length text from cells.

Davebro

Board Regular
Joined
Feb 22, 2018
Messages
135
Office Version
  1. 365
  2. 2021
  3. 2016
Platform
  1. Windows
Trying to extract the two text names to columns B & C

2.00 Space Tourist 4.50 Cash The Cheque
2.38 Arctic Ambition 4.00 Sheephaven Flyer
2.50 Ocean Baroque 4.20 King Cuan
3.00 Snowcapped 4.33 Impact Warrior
3.50 Rathnaleen Kal 6.00 Atimetodream
2.10 Mashadi 4.50 Succession
2.88 Veil Of Shadows 5.50 Araminta
2.00 Dream Composer 5.00 Lihou
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Data -Text to columns - Use space as delimiter and in the last window of the wizard select "Do not import" irrelevant columns
 
Upvote 0
Thank you for your eply but this seems to spread the text to column F, does not seperate the names.
 
Upvote 0
Thank you for your eply but this seems to spread the text to column F, does not seperate the names.
Can you show us the expected results of your original data?
We want to be sure that we fully understand what parts of the strings are the "names" that you are trying to pull (or is it just everything in-between/after the numbers)?
 
Upvote 0
Can you show us the expected results of your original data?
We want to be sure that we fully understand what parts of the strings are the "names" that you are trying to pull (or is it just everything in-between/after the numbers)?
2.00 Space Tourist 4.50 Cash The ChequeSpace TouristCash The Cheque
2.38 Arctic Ambition 4.00 Sheephaven Flyer
2.50 Ocean Baroque 4.20 King Cuan
3.00 Snowcapped 4.33 Impact Warrior
3.50 Rathnaleen Kal 6.00 Atimetodream
2.10 Mashadi 4.50 Succession
2.88 Veil Of Shadows 5.50 Araminta
2.00 Dream Composer 5.00 Lihou
 
Upvote 0
If my assumption is correct, and every number has a "." in it, then you can create your own function in VBA to do this.
I started with some code I borrowed from here: How to remove / split text and numbers in Excel cell
and came up with this code:
VBA Code:
Function RemoveNumbers(str As String, num As Byte) As String
'   Started with code borrowed from here: https://www.ablebits.com/office-addins-blog/remove-text-numbers-from-string-excel/
'       "str" is the string you want to parse
'       "num" is the number of the name you want to return
       
    Dim temp As String
    Dim arr() As String

'   Remove numbers
    With CreateObject("VBScript.RegExp")
        .Global = True
        .Pattern = "[0-9]"
        temp = .Replace(str, "")
    End With
   
'   Split string on period
    arr = Split(temp, ".")
   
'   Return designated word and trim leading/trailing spaces
    RemoveNumbers = Trim(arr(num))
   
End Function
All you need to do is to insert a new module in the VB Editor for this workbook, and copy and paste that code there.
Then you can use it like any other function in your workbook, i.e. to return the first name from an entry in cell A2, you would use:
Excel Formula:
=RemoveNumbers(A2,1)
To return the second name, you would use:
Excel Formula:
=RemoveNumbers(A2,2)

So based on your data, here is what the results would look like:
1685111339718.png
 
Upvote 0
If my assumption is correct, and every number has a "." in it, then you can create your own function in VBA to do this.
I started with some code I borrowed from here: How to remove / split text and numbers in Excel cell
and came up with this code:
VBA Code:
Function RemoveNumbers(str As String, num As Byte) As String
'   Started with code borrowed from here: https://www.ablebits.com/office-addins-blog/remove-text-numbers-from-string-excel/
'       "str" is the string you want to parse
'       "num" is the number of the name you want to return
     
    Dim temp As String
    Dim arr() As String

'   Remove numbers
    With CreateObject("VBScript.RegExp")
        .Global = True
        .Pattern = "[0-9]"
        temp = .Replace(str, "")
    End With
 
'   Split string on period
    arr = Split(temp, ".")
 
'   Return designated word and trim leading/trailing spaces
    RemoveNumbers = Trim(arr(num))
 
End Function
All you need to do is to insert a new module in the VB Editor for this workbook, and copy and paste that code there.
Then you can use it like any other function in your workbook, i.e. to return the first name from an entry in cell A2, you would use:
Excel Formula:
=RemoveNumbers(A2,1)
To return the second name, you would use:
Excel Formula:
=RemoveNumbers(A2,2)

So based on your data, here is what the results would look like:
View attachment 92378

That's terrific, many thanks for your help.
 
Upvote 0
You are welcome.
Glad we were able to help!
 
Upvote 0

Forum statistics

Threads
1,223,901
Messages
6,175,277
Members
452,629
Latest member
SahilPolekar

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