Getting multiple values between two different characters.

SpencerC

New Member
Joined
Dec 8, 2017
Messages
4
Hello all,

I have a list of values that look like this: ;Asphalt Late Model>Rear Suspension;Road Race>Rear Suspension


What I need to do is get all of the values between ; & >.


So in this example the output would be Asphalt Late Model;Road Race


Any help would be very appreciated, as I've been stuck on this one for a while.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
paste this macro and run...

Code:
Sub aParseData()
Dim vWord, vOut, vClip
Dim iStart As Integer, iEnd As Integer

Range("A2").Select
While ActiveCell.Value <> ""
   vWord = ActiveCell.Value
   iStart = InStr(vWord, ";")
   While iStart > 0
        iEnd = InStr(vWord, ">")
        vClip = Mid(vWord, iStart + 1, iEnd - iStart - 1)
        vOut = vOut & vClip & ";"
        vWord = Mid(vWord, iEnd + 1)
        iStart = InStr(vWord, ";")
   Wend
   ActiveCell.Offset(0, 1).Value = vOut
   vOut = ""
   ActiveCell.Offset(1, 0).Select   'next row in source
Wend
End Sub
 
Last edited:
Upvote 0
Thank you for this macro, it does parse the data correctly but it is giving me an error "run-time error '5': invalid procedure call or argument" and when I hit debug it is highlighting the vClip line. Any ideas? Thank you for the help!
 
Upvote 0
Istvan, your formula seems to only parse the first result, instead of all results in the cell. Any ideas? Thank you!
 
Upvote 0
ranman256, its my bad that I didn't mention it, but the amount of values can vary so I can have cells like:

;Dirt Late Model/Modified>Engine>Other Engine;Drag Race>Engine>Other Engine;Off Road>Engine>Other Engine;Asphalt Late Model>Engine>Other Engine;Road Race>Engine>Other Engine
 
Upvote 0
Try this,

Code:
[COLOR=#0000cd]Sub SplitParse()

Dim str1        As String
Dim n           As Long
Dim arr1
Dim part

str1 = Range("A2").Value2
arr1 = Split(str1, ";")
n = 2
For Each part In arr1
    If InStr(1, part, ">") > 0 Then
        Range("B" & n) = Trim$(Mid(part, 1, InStr(1, part, ">") - 1)) [/COLOR][COLOR=#d3d3d3]'& ";"[/COLOR][COLOR=#0000cd]
        n = n + 1
    End If
Next
Columns("B:B").Columns.AutoFit

End Sub[/COLOR]
 
Upvote 0
Try this,

Code:
[COLOR=#0000cd]Sub SplitParse()

Dim str1        As String
Dim n           As Long
Dim arr1
Dim part

str1 = Range("A2").Value2
arr1 = Split(str1, ";")
n = 2
For Each part In arr1
    If InStr(1, part, ">") > 0 Then
        Range("B" & n) = Trim$(Mid(part, 1, InStr(1, part, ">") - 1)) [/COLOR][COLOR=#d3d3d3]'& ";"[/COLOR][COLOR=#0000cd]
        n = n + 1
    End If
Next
Columns("B:B").Columns.AutoFit

End Sub[/COLOR]

It extracts the string if there is no semicolon, for example, from "Rear suspension>and others".
 
Upvote 0
Try this:

=TRIM(MID(SUBSTITUTE(SUBSTITUTE(";"&$A2,";",">"),">",REPT(" ",200)),200*2*COLUMNS($A:A),200))

Better version (enter into B2, copy across and down):

=MID(SUBSTITUTE(SUBSTITUTE($A2,";","$",COLUMNS($A:A)),">","ß",COLUMNS($A:A)),FIND("$",SUBSTITUTE(SUBSTITUTE($A2,";","$",COLUMNS($A:A)),">","ß",COLUMNS($A:A)))+1,FIND("ß",SUBSTITUTE(SUBSTITUTE($A2,";","$",COLUMNS($A:A)),">","ß",COLUMNS($A:A)))-FIND("$",SUBSTITUTE(SUBSTITUTE($A2,";","$",COLUMNS($A:A)),">","ß",COLUMNS($A:A)))-1)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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