VBA to replace/remove

tourless

Board Regular
Joined
Feb 8, 2007
Messages
144
Office Version
  1. 365
Platform
  1. Windows
Hi Folks,

I have a list of customers in column A. All of them start with "zz" which is simple enough to remove using...
Range("A2:A" & lRow).Replace what:="zz", Replacement:="", _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, _
SearchFormat:=False, ReplaceFormat:=False
In that same list there are a variety of possible ending characters that I would like to remove as well. Some customers end with just their name which is fine. Others might end with "***OOB" or "***PO" or "***QT" or some variety therein. What I would like to do is any time the * character is found, remove it and anything that comes after it. I've tried variations on the following with no luck so far...
Range("A2:A" & lRow).Replace what:="(*)", Replacement:="", LookAt:=xlPart

UPDATE:
This has gotten me closer...
Range("A2:A" & lRow).Replace what:=" ~*", Replacement:="", LookAt:=xlPart

TIA!
 
Last edited:

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
How about
Code:
Range("A2:A" & LRow).Replace "~**", "", xlPart, , False, , False
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
You need a minor tweak to your code: use Range("A2:A" & lRow).Replace what:=" ~**", Replacement:="", LookAt:=xlPart
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,203
Members
452,617
Latest member
Narendra Babu D

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