extracting a string

ajm

Well-known Member
Joined
Feb 5, 2003
Messages
2,005
Office Version
  1. 365
Platform
  1. Windows
hi, i am looking to extract a string of text from within a sentence. The string consists of 6 characters or less (4 minimum) with the last three chartacters "HHS" and in 90% of cases, comes after a space. Sometimes, though the string is at the beginning of the sentence. I tried trimming the results of a mid statement using Find to locate the substring (HHS) and then subtracted 3 to get to the start of the string:

(TRIM(MID([@Provider], FIND("HHS",[@Provider])-3,6))

That worked in most cases where the full string is either 6 characters or five in length. It didn't work where the string was at the beginning of the sentence, nor if the length was only 4 characters.

so, how can you extract a string containing "HHS" as the last three characters, where the string is max 6 characters, but could be 5 or 4, that will have a space before it if its at the end of the sentence, but not if its at the start.

examples might be:

Jonnos space ABCHHS
Monkey Gone Bananas - MHHS
Hoots Boots WBHHS Man
XYZHHS Area 54 Open to all ages
Cows Horses Dogs CHHS
 
Upvote 0

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,214,646
Messages
6,120,720
Members
448,986
Latest member
andreguerra

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