Formula Needed to Extract Middle Part of String

DougStroud

Well-known Member
Joined
Aug 16, 2005
Messages
2,968
This is a separate formula request.
This related to a recent post, http://www.mrexcel.com/board2/viewtopic.php?p=1392308#1392308,
but different. The function of this one is to extract the middle string between the two colons, and remove the leading and trailing spaces.
I cannot get the middle string by itself.

I think maybe the MID function is a possibility, but I have failed to implement it properly.

=IF(LEN($AB36)-LEN(SUBSTITUTE($AB36,":",""))<1,"",IF(LEN($AB36)-LEN(SUBSTITUTE($AB36,":",""))=1,RIGHT($AB36,LEN($AB36)-FIND(" ",$AB36)-2),IF(LEN($AB36)-LEN(SUBSTITUTE($AB36,":",""))=2,RIGHT($AB36,LEN($AB36)-FIND(" ",$AB36)-2))))

Guys : Beanies & Hats : Beanies
Here I need
Beanies & Hats

The second IF looks to see if there is one colon delimiter and returns the last value. The last IF looks to see if there are two colon delimiters, if this is true, then I need the middle string.
I am failing here. I recognize I am using the RIGHT Function, I am not able to write the MID function correctly, so I have left it out for example sake.

Thanks for any input/assistance.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Doug

Have you ever considered using UDFs for this?

For example you could easily extract that string using the Split function in a UDF.
 
Upvote 0
Yes and no....
Why I am avoiding the UDF at the moment. I feel it crucial to learn how to write formulas to deal w/ such scenarios, the reason being is to develop my overall Excel skills and knowledge.
Secondly, I have the surrounding values being returned w/ formulae and like to maintain the consistency, for future edits and understanding of the way the values are derived.

The UDF is still beyond my grasp currently and would rather take these thing, meaning my learning approach in chunks. As you know, I am still working on VBA basics, so I am somewhat resistant to using a different method which opens up the door for other issues. If I were just looking to get an answer, that would be ok.... know what I mean?

But I am hoping to find an answer w/ the formulae and if that is not possible, then of course I am open to a different method.
 
Upvote 0
If D8 has my value,
This worked for me:

Code:
=MID(D8,FIND(":",D8)+1,(FIND(":",D8,FIND(":",D8)+1)-FIND(":",D8))-1)

Michael
 
Upvote 0
Doug

I'm pretty sure there is a formula answer, but as you probably know I'm no formula guru.:)

If something like this came my way I'd immediately think of using code.

Perhaps the Split function as I suggested, or even Data>Text to columns...
Code:
Function GetMiddleBit(rng)
    x = Split(rng.Value, ":")
    GetMiddleBit = Trim(x(1))
End Function
 
Upvote 0
Thanks Daniel!
This close... There are leading and trailing spaces.
I will muck around w/ this and see if I can find how to remove... maybe the Trim
 
Upvote 0
Daniel-
Bravo- Thanks....
This got it....=IF(LEN($AB36)-LEN(SUBSTITUTE($AB36,":",""))<1,"",IF(LEN($AB36)-LEN(SUBSTITUTE($AB36,":",""))=1,
RIGHT($AB36,LEN($AB36)-FIND(" ",$AB36)-2),IF(LEN($AB36)-LEN(SUBSTITUTE($AB36,":",""))=2,TRIM(MID(AB36,FIND(":",AB36)+1,(FIND(":",AB36,FIND(":",AB36)+1)-FIND(":",AB36))-1)))))
 
Upvote 0
No worries Norie....
I will hit you up when I get to UDFs, how is that? This stuff is like the future, I know its coming, not just sure when... :)
 
Upvote 0
This should be a colon instead of a comma.
=TRIM(LEFT(RIGHT(SUBSTITUTE(B2,":",REPT(" ",40)),80),40))

John
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

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