Macro to replace ONLY x's with blank

JugglerJAF

Active Member
Joined
Feb 17, 2002
Messages
297
Office Version
  1. 365
Platform
  1. Windows
I have a customer data file in which some cells have been completed with x's and I need to replace any cell that contains x's with a blank.

I can easily do this when the cell contains a single x by using find and replace within the macro, but some customers have completed fields with xx or xxx or xxxx and so on - these x's may be in upper or lower case.

I can't just replace all instances of x (or X) with blank on partial cells as there will be company names or address details that will contain an x.

What I need is a way to identify cells that contain ONLY x character(s): so "x" would be replaced with blank as would "xx", "xxx" etc., but "XYZ Limited", "LOXX & Co." or "Essex" need to be left as is.

I can't even think where to begin on this. Anyone got any bright ideas or can point me in the right direction?

Thanks
JAF
 
VOG's code works fine for me - must be something about the Mac version (Mike Rickson could tell us!)

@Juggler
Sorry that I missed your instructions - I was thinking the x's would all be single x's.

Without VBA you might try:

1) Replacing all "xx" with nothing (partial matches allowed)
2) Replace all single "x" (whole matches only)

That should eliminate everything - but we assume there are no "Essexx" or "XXray" values! XX seems a rare character combination to me so it should work - or go with VOG's macro which won't have any such loopholes.
 
Last edited:
Upvote 0

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Try this

Code:
Sub DelX()
Dim c As Range
For Each c In ActiveSheet.UsedRange
    With c
        If Replace(LCase(.Value), "x", "") = "" Then .Value = ""
    End With
Next c
End Sub

Works a treat. Many thanks.
JAF
 
Upvote 0

Forum statistics

Threads
1,214,929
Messages
6,122,315
Members
449,081
Latest member
tanurai

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