Forum

Extract code from s...
 
Notifications
Clear all

[Solved] Extract code from string in a cell

5 Posts
2 Users
0 Reactions
611 Views
(@erik_h_dk)
Posts: 45
Trusted Member
Topic starter
 

Hi to all of you

At work my boss has challenged me to extract a code from a string in a cell. 

The code is like 4 characters (can be letters and numbers)-5 numbers-5 numbers-year (2 numbers)

Example: AB42-12345-54615-25. Letters can be upper and/ or lower case.

In most cases the code has text and or numbers before and after - and always parted with a space on either side. 

Example - "this is a test AB42-12345-54615-25 sold august 30. 2025"

Can any of you help me - in Power Query or otherwise to extract the code to a new column ?

In this example it would be - "AB42-12345-54615-25"

 

At work the file has 100.000 plus rows, so it will save me a lot of time.

 

Thank you

Erik

 

 


 
Posted : 30/08/2025 9:17 pm
Riny van Eekelen
(@riny)
Posts: 1441
Member Moderator
 

@erik_h_dk

Must you do this in PQ?

Quite easy to do it in Excel. Have a look at the attached. Not very difficult to replicate this in PQ as well. Find the location of the first "-", minus 4 and then extract the next 19 characters.


 
Posted : 31/08/2025 3:39 am
(@erik_h_dk)
Posts: 45
Trusted Member
Topic starter
 

Thanks a lot Riny - you are a life saver.

This task is not a one time thing, and in my experience a Power Query solution is less vulnerable to others using Excel - adding columns, rows or lacking skills using formulas. 

But your solution is the one I will be using - Thank you

Erik


 
Posted : 31/08/2025 3:54 pm
Riny van Eekelen
(@riny)
Posts: 1441
Member Moderator
 

@erik_h_dk 

Glad I could help. As mentioned before, it's not difficult in PQ either. So, if you prefer using PQ, please see the attached file.

 


 
Posted : 31/08/2025 7:45 pm
(@erik_h_dk)
Posts: 45
Trusted Member
Topic starter
 

Thanks again Riny

I really appreciate your help.

Erik


 
Posted : 31/08/2025 8:57 pm
Share:
0