Excel Function to extract a substring from a string ?

Maverick27

Active Member
Joined
Sep 23, 2010
Messages
329
Office Version
  1. 2013
Platform
  1. Windows
Can someone pls help me with a Excel Function (or VBA Code) to extract a substring from a string ?

I need the Text btwn the 1st ">" AND 2nd ">" from the RIGHT & output to another col. Example below.

String Example:
HEALTH & BEAUTY|HEALTH & BEAUTY > Health Care|HEALTH & BEAUTY > Mobility Devices > Wheel Chair

Substring Output:

Mobility Devices

Thanks.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Here's a VBA method:
Code:
Function ExtractStringFromRight(ByVal sText As String, ByVal lNumber As Long, Optional sDelimiter As String = ">") As String
    Dim vParts
    vParts = Split(sText, sDelimiter)
    If UBound(vParts) >= lNumber Then
        lNumber = UBound(vParts) - lNumber + 1
        ExtractStringFromRight = Trim$(vParts(lNumber))
    End If
End Function

Then assuming your text is in A1, you'd enter:
=ExtractStringFromRight(A1,2)
in another cell.
 
Upvote 0
Here's a VBA method:
Code:
Function ExtractStringFromRight(ByVal sText As String, ByVal lNumber As Long, Optional sDelimiter As String = ">") As String
    Dim vParts
    vParts = Split(sText, sDelimiter)
    If UBound(vParts) >= lNumber Then
        lNumber = UBound(vParts) - lNumber + 1
        ExtractStringFromRight = Trim$(vParts(lNumber))
    End If
End Function

Then assuming your text is in A1, you'd enter:
=ExtractStringFromRight(A1,2)
in another cell.


Thanks - it works.
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,552
Members
449,088
Latest member
davidcom

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