Pulling out Code from Text String

ccecil02

New Member
Joined
Aug 12, 2015
Messages
10
Hello all!

I'm looking to pull out a code from the middle of a text string. The codes are always 22 characters long and come after the phrase "Code:"

Example in cell C4: Welcome! Get $X off $X purchase. Code:xxxxxxxxxxxxxxxxxxxxxxxxxx EXP {{date:MM/dd|+30d}} Excl Apply.Approx 5 auto txts/mo.TERMS=T&CsSTOP=endHELP=help Msg&DataRatesMayApply

I feel like I've tried some things I've seen on here and I get results that don't quite work when it seems they should.

Thanks in advance for your help!!
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
try this:
Code:
=MID(C4,FIND(":",C4)+1,22)

Put that in the cell you want to have the information show up.
 
Upvote 0
So I modified it to this, =MID(C335977,FIND("Code:",C335977)+5,23)

How would I modify it further if it's sometimes listed as "Code:" and other times as "Cod:"
 
Upvote 0
No reason to look for the "code" or "cod" part as both end in the colon ":", so just do the find on the colon.
 
Upvote 0
No reason to look for the "code" or "cod" part as both end in the colon ":", so just do the find on the colon.

There's some other text at the beginning on the message that has a colon as well (I omitted from first post on accident) so I think that's where I'm running into an issue when keying on the colon.
 
Upvote 0
Try this then:

Code:
=IF(ISERROR(FIND(":",C4)),"No Code",IF(ISERROR(FIND("cod:",C4)),MID(C4,FIND("code:",C4)+5,22),MID(C4,FIND("cod:",C4)+4,22)))

It will spit out "No Code" if there is no colon located in C4, otherwise it will look for both "cod:" and "code:" and give you the output
 
Upvote 0

Forum statistics

Threads
1,215,727
Messages
6,126,508
Members
449,316
Latest member
sravya

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