Extract text between second and first space from the right in text string

CaptainGravyBum

Board Regular
Joined
Dec 1, 2023
Messages
77
Office Version
  1. 365
Platform
  1. Windows
Book1
A
1SG EQUIPMENT FINAN A096031949 DDR
2DE LAGE LANDEN LEA 24350098914 DDR
Sheet1


Hello,
I need to extract the reference number from the text strings above, I have many rows of data that my formula needs to work on, but these two should serve as suitable examples.
The reference always sits after the second space from the right and I don't need any of the information after the first space from the right. The number isn't always the same length and the number of spaces before the reference number do change as you can see in the example, so it strongly relies on a search for the number of spaces from the right which remain the same.
I've tried various MID, LEFT, RIGHT, SEARCH combinations, but I can't quite get it to consider the variable lengths of data.

I appreciate any help you can give.
 

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)
You're welcome & thanks for the feedback.
 
Upvote 0
You're welcome & thanks for the feedback.
I've applied the formula to my data and discovered that not all references follow the same criteria. Do you have something I could use that just looks for numbers in the string and returns the data from that?
The number will always have a space after it so ideally it would be something along the lines of finding the space after the number and returning all data preceding the space until it hits another space, purely because the number sometimes has a letter preceding it.
Sorry if this sounds like nonsense.
 
Upvote 0
Ah, fair enough.
The original sample data will work, but I've provided a few more here so you can see where the rule of picking up data from the second space from the right is failing (row 2).

Book2
A
1ALDERMORE BANK PLC C0015954106168976 DDR
2DE LAGE LANDEN LEA 24350418751 FIRST DDR PAYMENT DDR
3DE LAGE LANDEN LEA 24350418751 DDR
Sheet1
 
Upvote 0
Maybe this. This looks for the last numeric position in the string and extracts the chunk of text with the last numeric character.
Book1
AB
1ALDERMORE BANK PLC C0015954106168976 DDRC0015954106168976
2DE LAGE LANDEN LEA 24350418751 FIRST DDR PAYMENT DDR24350418751
3DE LAGE LANDEN LEA 24350418751 DDR24350418751
4SG EQUIPMENT FINAN A096031949 DDRA096031949
5DE LAGE LANDEN LEA 24350098914 DDR24350098914
Sheet12
Cell Formulas
RangeFormula
B1:B5B1=LET(x,XMATCH(TRUE,ISNUMBER(--MID(A1,SEQUENCE(LEN(A1)),1)),0,-1), TEXTAFTER(LEFT(A1,x)," ",-1))
 
Upvote 0
Solution

Forum statistics

Threads
1,223,885
Messages
6,175,183
Members
452,615
Latest member
bogeys2birdies

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