Macro for Find and Replace a Value in a Cell with Corresponding Value in Column in MS Excel 2010

ashchow1986

New Member
Joined
May 21, 2011
Messages
3
I need to write Macro for this. Column 1 has the original values and Column 2 has the values that should be replaced in Column 1.

Column1 Column2
ABC | QWE
qqq | ASH
ERTR | PRR
qqq | DIA

Find for "qqq" in each row and replace with corresponding column 2 value.

After replacement it should look like:

Column1
ABC
ASH
ERTR
DIA

I have written a simple macro for each and every row. But I need to do this using loop for the entire Sheet so that I don't keep on writing for every row individually. I'm new to this and not sure of how to write a macro for this.

Any help would be great.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Do you want to delete the column 2 values at the same time? Assuming not perhaps:

Code:
Dim cell As Range

For Each cell In Range("A1",Cells(Rows.Count,"A").End(xlUp))
  If cell.Value = "qqq" Then _
     cell.Value = cell.Offset(,1).Value
Next cell
 
Upvote 0
This is what I wanted. Thanks a lot :)
I was wondering what if the cell values to be replaced are not all in the same column.

Column1 Column2 Column 3
ABC | QWE |
qqq | ASH |
ERTR | PRR |
qqq | | DIA

Final output remains the same.
How to do this in one single loop?
 
Upvote 0
If there is nothing immediately to the right of these values, try just changing the second last line of Richard's code to
Code:
cell.Value = cell.End(xlToRight).Value
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,265
Members
452,627
Latest member
KitkatToby

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