Find/Replace Macro

rmsbcb

New Member
Joined
Nov 18, 2005
Messages
6
I have a column with the following data
cat (dog)
blue
blue (dog)
blue (cat)
How can I write a macro to find all cells within the column that contain "(dog)" and replace the entire contents of the cell with "dog"?
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
When I used that it replaced "(dog)" with "dog" within the cell I need every cell that contains "(dog)" either by itself or as part of a list to be replaced with just "dog"
 
Upvote 0
you can use wildcards to replace the whole string:

Code:
[A1:A20].Replace What:="*(dog)*", Replacement:="dog"

this replaces anything with (dog) in it with just "dog"
 
Upvote 0
Find/Replace use settings from the last pass, so if you're wanting to replace partial cell contents, best to be explicit --

... .Replace What:="xx", Replacement:="x", LookAt:=xlPart
 
Upvote 0

Forum statistics

Threads
1,223,566
Messages
6,173,093
Members
452,501
Latest member
musallam

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