How to find a code within a string of text

EmmaTM

Board Regular
Joined
Jan 5, 2022
Messages
74
Office Version
  1. 365
Platform
  1. Windows
Hi, I have a column with a string of text that can have different numbers of characters. I want to be able to extract the account number shown below in red so that I can do a look up with a list of customer account codes on another tab. I cannot use left or right as I said the numbers before and after will always be different.

Contractor Timesheet Pay~GEN000000000~M100004CA~E Pppp~79347~SSS Ltd~2023~1

Thank you
Emma
 
In what way didn't it work?
It works for me
Fluff.xlsm
AB
1
2Contractor Timesheet Pay~GEN000000000~M100004CA~E Pppp~79347~SSS Ltd~2023~179347
3Employers NIC Debit~GEN000000000~M10000PA~N Bbbbbb~79792~D Ltd~2023~179792
4Contractor Timesheet Pay~GEN00000000~M20000CA~S Hhhhhh~80041~T Ltd~2023~180041
Data
Cell Formulas
RangeFormula
B2:B4B2=FILTERXML("<k><m>"&SUBSTITUTE(A2,"~","</m><m>")&"</m></k>","//m[5]")
 
Upvote 0

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
As you can see from post#11 it works for me, but try the formula in col C
Fluff.xlsm
ABC
1
2Contractor Timesheet Pay~GEN000000000~M100004CA~E Pppp~79347~SSS Ltd~2023~17934779347
3Employers NIC Debit~GEN000000000~M10000PA~N Bbbbbb~79792~D Ltd~2023~17979279792
4Contractor Timesheet Pay~GEN00000000~M20000CA~S Hhhhhh~80041~T Ltd~2023~18004180041
Data
Cell Formulas
RangeFormula
B2:B4B2=FILTERXML("<k><m>"&SUBSTITUTE(A2,"~","</m><m>")&"</m></k>","//m[5]")
C2:C4C2=REPLACE(LEFT(A2,FIND("^",SUBSTITUTE(A2,"~","^",5))-1),1,FIND("^",SUBSTITUTE(A2,"~","^",4)),"")
 
Upvote 0
Solution
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,047
Messages
6,122,858
Members
449,096
Latest member
Erald

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