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

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
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,223,910
Messages
6,175,316
Members
452,634
Latest member
cpostell

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