Remove prefix/suffix text with excel/vba

STEEL010

Board Regular
Joined
Dec 29, 2017
Messages
76
Hi There,

Maybe someone can help.

I want to remove prefix/suffix text in text cell like below.

situation now:
PL_hftyo_BARCODE LABELS

change to:
BARCODE LABELS

it must be variable because the prefix/suffix is not fixed with the same length

Regards,
Steel010
 
My previous quote was not answered, can you guys still help?

"I have only have one more question about the prefix, is it possible that it stops at the seconde "_" underscore. because I have some text with more underscore but these are no prefix's."

PL_hftyo_BARCODE_LABELS_FOR_ORDERS
See if this code works for you...
Code:
[table="width: 500"]
[tr]
	[td]Sub RemovePrefix()
  Dim Addr As String
  Addr = "A1:A" & Cells(Rows.Count, "A").End(xlUp).Row
  Range(Addr) = Evaluate(Replace("IF({1},LEFT(@,FIND(""_"",@&""__"",FIND(""_"",@&""_"")+1)-1))", "@", Addr))
End Sub[/td]
[/tr]
[/table]
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi Rick,

:rolleyes: it leaves only this part PL_hftyo_ the part that I want is after the second underscore.
Sorry, try this macro then...
Code:
[table="width: 500"]
[tr]
	[td]Sub RemovePrefix()
  Dim Addr As String
  Addr = "A1:A" & Cells(Rows.Count, "A").End(xlUp).Row
  Range(Addr) = Evaluate(Replace("IF({1},REPLACE(@,1,FIND(""_"",@&""__"",FIND(""_"",@&""_"")+1),""""))", "@", Addr))
End Sub[/td]
[/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,394
Members
448,957
Latest member
Hat4Life

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