I had an error, which is corrected in the attached but the formula becomes very unwieldy compared to the ones above.
I have also added a UDF here if you care to use one, also in the attached.
' Extract the nth occurrence of text delimited by ldelim and rdelim, including the
' delimiters
Public Function DelimitedText( _
c As Range, _
ldelim As String, _
rdelim As String, _
Optional n As Long = 1) _
As String
Dim s As Variant
Dim stemp As String
Dim result As Variant
result = InStr(c.Value, ldelim)
If result = 0 Then
DelimitedText = "#LDELIM!" ' left delimited not found
Else
s = Split(c.Value, ldelim)
stemp = ldelim & s(n)
result = InStr(stemp, rdelim)
If result = 0 Then
DelimitedText = "#RDELIM!" ' right delimiter not found
Else
DelimitedText = Mid(stemp, 1, InStr(stemp, rdelim))
End If
End If
End Function
Bookmarks