Extracting substring from within a string

ChrisLane

New Member
Joined
May 22, 2014
Messages
38
Good afternoon

I have a string in a cell that contains a substring that I need to extract. The string is as follows"

AGTCode=00291323*CargoCarrier=ZZZ00028*Carrier=COS*MasterBillIssuedDate=2022-07-14 00:00:00.000*RadioCallSign=VRMN9*RL_NKMasterBillIssuedAt=CNNGB*VATClaimBackIndicator=Y

This string is the contents of a field within a record in an SQL Server table that I have extracted to Excel as part of a VIEW.

What I am trying to achieve is to extract the substring Carrier=COS.

The "Carrier" in the shipping line, and the "COS" is their customs carrier code.

The record can contain two fields: a job number, and the above, so I would like to extract two columns, the job number and the carrier code.

Complications? As you can see, "elements" in the string are encapsulated in asterisks - the Carrier Code element can be second in the list, or third, and the carrier code can consist of 3 or 4 characters.

If I was just using Excel, I could use the TEXT TO COLUMNS function, but not in this situation as I am compiling a report that needs the two columns mentioned above (job number, and carrier code).

I would appreciate any help I could get, please.

Many thanks
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
There may be a more efficient way but this seems to work:
=MID(A1,FIND("*Carrier=",A1,1)+1,FIND("*",A1,40)-1-FIND("*Carrier=",A1,1))
 
Upvote 0

Forum statistics

Threads
1,224,543
Messages
6,179,429
Members
452,914
Latest member
echoix

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