Extract text from string

saltkev

Active Member
Joined
Oct 21, 2010
Messages
324
Office Version
  1. 2013
Platform
  1. Windows
VBA

Good Morning Guys
I hope you can help. I need to extract specific pieces of text from a string. The string will differ in length but will keep the same format between "/"

The pieces of text are identified in RED. There will thousands of lines so I will run it through a For Loop

2 ;V5745463100800/UBN1/N/1/0/10/50313213/1

Many Thanks

Kev

 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

Can you tell us what it is that identifies exactly what is is that has to be extracted?
 
Upvote 0
Hi

The First piece of text is always preceeded by a semi-colon ";" and ends prior to the first obleque "/"
The Second piece of text always starts imediatly after the 5th Oblique "/" and ends prior to the 6th Oblique "/"

Kev
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

Can you tell us what it is that identifies exactly what is is that has to be extracted?
Hi

The First piece of text is always preceeded by a semi-colon ";" and ends prior to the first obleque "/"
The Second piece of text always starts imediatly after the 5th Oblique "/" and ends prior to the 6th Oblique "/"

Kev
 
Upvote 0
Thanks for the extra information, but what about the first thing I suggested?

suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
In the meantime, see if this helps. It assumes the data is in column A
Test with a copy of your workbook.
VBA Code:
Sub ExtractText()
  With Range("A1", Range("A" & Rows.Count).End(xlUp))
    .Offset(, 1).Value = Evaluate(Replace("if(#="""","""",replace(left(#,find(""/"",#&""/"")-1),1,find("";"",#),""""))", "#", .Address))
    .Offset(, 2).Value = Evaluate(Replace("trim(mid(substitute(#,""/"",REPT("" "",100)),500,100))", "#", .Address))
  End With
End Sub
 
Upvote 0
Not sure what more you want?
I wanted to know your Excel version. I see that you have updated it now but it was not showing for me at the time I asked.
Anyway, let's see what the result of my code suggestion is.
 
Upvote 0
In the meantime, see if this helps. It assumes the data is in column A
Test with a copy of your workbook.
VBA Code:
Sub ExtractText()
  With Range("A1", Range("A" & Rows.Count).End(xlUp))
    .Offset(, 1).Value = Evaluate(Replace("if(#="""","""",replace(left(#,find(""/"",#&""/"")-1),1,find("";"",#),""""))", "#", .Address))
    .Offset(, 2).Value = Evaluate(Replace("trim(mid(substitute(#,""/"",REPT("" "",100)),500,100))", "#", .Address))
  End With
End Sub
Not sure what more you want?
I can now see your reply,

The first line is working well the second not working, P.S the data is in "B", I changed your ranges, or I can copy to Col "A"

Thanks fort your help
 
Upvote 0
I can now see your reply,

The first line is working well the second not working, P.S the data is in "B", I changed your ranges, or I can copy to Col "A"

Thanks fort your help
Results

result.JPG
 
Upvote 0
OK Range mistake on my part now working a little better but is taking second piece of text from "B2" and repeating

1668603371878.png
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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