ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Grabbing a String between two delimiters (https://www.excelbanter.com/excel-programming/272870-grabbing-string-between-two-delimiters.html)

Kirk[_2_]

Grabbing a String between two delimiters
 
For some reason I can't seem to figure this one out. I
need to be able to determine a string that lies between
two delimeters.

Example:

xyz\abc\defgh

I need to be able to grab out the "abc" portion without
knowing the exact size of what the string will be between
the two delimters (\). In looking at a book I have there
was mention of a function called dhExtractString but it
appears not to work on Excell 2002 (SP2) unless there is
a reference that I need to add.

Any help would be appreciated. Thanks.

Kirk

Chip Pearson

Grabbing a String between two delimiters
 
Kirk,

Use the Split function. E.g.,

Dim S As String
Dim Arr As Variant
S = "xyz\abc\defgh"
Arr = Split(S, "\")
MsgBox Arr(1)


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Kirk" wrote in message
...
For some reason I can't seem to figure this one out. I
need to be able to determine a string that lies between
two delimeters.

Example:

xyz\abc\defgh

I need to be able to grab out the "abc" portion without
knowing the exact size of what the string will be between
the two delimters (\). In looking at a book I have there
was mention of a function called dhExtractString but it
appears not to work on Excell 2002 (SP2) unless there is
a reference that I need to add.

Any help would be appreciated. Thanks.

Kirk




Kent Prokopy[_3_]

Grabbing a String between two delimiters
 
Try using the following function...

Debug.Print strReturnValue("xyz/abc/defgh","/","/")

Public Function strReturnValue(strMessageBody As String, strTag1 As String,
strTag2 As String) As String
Dim StartPos As Long
Dim EndPos As Long
StartPos = InStr(1, strMessageBody, strTag1, vbTextCompare) + Len(strTag1)
EndPos = InStr(StartPos, strMessageBody, strTag2, vbTextCompare)
If EndPos = 0 Then EndPos = StartPos
strReturnValue = Mid(strMessageBody, StartPos, EndPos - StartPos)
End Function


"Kirk" wrote in message
...
For some reason I can't seem to figure this one out. I
need to be able to determine a string that lies between
two delimeters.

Example:

xyz\abc\defgh

I need to be able to grab out the "abc" portion without
knowing the exact size of what the string will be between
the two delimters (\). In looking at a book I have there
was mention of a function called dhExtractString but it
appears not to work on Excell 2002 (SP2) unless there is
a reference that I need to add.

Any help would be appreciated. Thanks.

Kirk





All times are GMT +1. The time now is 05:22 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com