Macro to Replace content of a cell.

jbesclapez

Active Member
Joined
Feb 6, 2010
Messages
275
Hello Mr Excel, :biggrin:

I have a range from A:G
I have a column in I that tells what to find in the range
I have a column in J that tells with what to replace.
Those find/replace are in front of each other so : I1 is replaced by J1, I2 is replace by J2...
The find/replace as match the full content of the cell.

I hope my description is clear enough.

Thanks for your precious help.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Give this macro a try...
Code:
[table="width: 500"]
[tr]
	[td]Sub Replacements()
  Dim X As Long, FindReplace As Variant
  FindReplace = Range("I1", Cells(Rows.Count, "J").End(xlUp))
  For X = 1 To UBound(FindReplace)
    Columns("A:G").Replace FindReplace(X, 1), FindReplace(X, 2), xlWhole, , [B][COLOR="#FF0000"]True[/COLOR][/B], , False, False
  Next
End Sub[/td]
[/tr]
[/table]
Note: I assumed the values being searched for must be an exact match including the upper/lower case of the letters. If that guess was wrong, then change the red True highlighted above to False.
 
Last edited:
Upvote 0
Give this macro a try...
Code:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Sub Replacements()
  Dim X As Long, FindReplace As Variant
  FindReplace = Range("I1", Cells(Rows.Count, "J").End(xlUp))
  For X = 1 To UBound(FindReplace)
    Columns("A:G").Replace FindReplace(X, 1), FindReplace(X, 2), xlWhole, , [B][COLOR=#FF0000]True[/COLOR][/B], , False, False
  Next
End Sub[/TD]
[/TR]
</tbody>[/TABLE]
Note: I assumed the values being searched for must be an exact match including the upper/lower case of the letters. If that guess was wrong, then change the red True highlighted above to False.

Hello Rick,

What you did is perfect. Thanks a lot.
I am always amazed with the apparent simplicity of your work. You manage to make a difficult thing look simple in few lines.
Thanks again Rick, I wish you a great day
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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