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
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
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

Are there always 2 _'s?

If so try:

=RIGHT(RIGHT(A3, LEN(A3)-SEARCH("_", A3)), LEN(RIGHT(A3, LEN(A3)-SEARCH("_", A3)))-SEARCH("_", RIGHT(A3, LEN(A3)-SEARCH("_", A3))))

Replace A3 with whatever your cell reference is.
 
Upvote 0
Hi Finalfight40,

sometimes three.

But your formula works..... great.
how can I wright this into VBA, and auto replace exciting text with prefix/suffix.
 
Upvote 0
Hi Finalfight40,

sometimes three.

But your formula works..... great.
how can I wright this into VBA, and auto replace exciting text with prefix/suffix.

I couldn't put it into VBA myself, someone else might be able to help with that.

Best i could do is maybe adjust the one i gave you to include 3 instances of the underscores if that helps at all?
 
Upvote 0
Based on your sole example how about
Code:
Sub RemovePrefix()
Dim Cl As Range
For Each Cl In Range("A1", Range("A" & Rows.Count).End(xlUp))
   Cl.Value = Split(Cl.Value, "_")(UBound(Split(Cl.Value, "_")))
Next Cl
End Sub
 
Upvote 0
Hi Fluff,

I tried you VBA, but its does not work :(

this is my setup in excel see below:
MaterialMaterial DescriptionStorage Bin
5665RC_Gskt_GASKET SET2C111
9966RC_O-Ring_O-RING2C162
8888RC_Ring_RING, PISTON SEAL2C134
9966RC_Ring_RING, WIPER SET2C163



What I want is that it changes all text when I do a run in collum B staring from line 2



<tbody>
</tbody><colgroup><col><col><col><col><col></colgroup>
 
Upvote 0
If you want it to look at col B try
Code:
Sub RemovePrefix()
Dim Cl As Range
For Each Cl In Range("B2", Range("B" & Rows.Count).End(xlUp))
   Cl.Value = Split(Cl.Value, "_")(UBound(Split(Cl.Value, "_")))
Next Cl
End Sub
If this doesn't give the results you want, can you show us both before & after results.
 
Upvote 0
Your thread title says prefix/suffix, but all you seem to be asking for is the removal of a prefix. Given that, does this do what you want..
Code:
Sub RemovePrefix()
  Columns("B").Replace "*_", "", xlPart, , , , False, False
End Sub
 
Upvote 0
Hi there,

sorry for answering late, but Rick's methods works.

And sorry I have no suffix's.

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.

greetings Steel010
 
Upvote 0
Hi There,

Rick and Fluff (or someone else with great skills :) )


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

Greetings Steel010
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,387
Members
448,956
Latest member
JPav

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