VBA to replace text in cells/column under conditions

smide

Board Regular
Joined
Dec 20, 2015
Messages
162
Office Version
  1. 2016
Platform
  1. Windows
Hello.

On Sheet2, column B (B3:B600) I have a list of different products. Using array formula =IFERROR(INDEX($B$3:$B$600,MATCH(0,COUNTIF($D$2:D2,$B$3:$B$600),0)),"") I listed all products in column D (D3:D30).

In column E (E3:E30) I have a similar products like those ones in column D.

Problem: all text cells in column B identical to text in cell D3 should be replaced with text from cell E3, all text cells in column B identical to text in cell D4 should be replaced with text from cell E4 and so on...

*macro should replace this only on Sheet2 (not on other sheets)

example.

Sheet2 before macro run

A​
B​
C​
D​
E​
F​
1
2Products to replaceReplace with
3AppleAppleApple1
4OrangeOrangeOrangeX
5TomatoTomatoTomatoes
6Apple
7Tomato
8Orange

Sheet2 after macro run

A​
B​
C​
D​
E​
F​
1
2
Products to replace
Replace with
3Apple1AppleApple1
4OrangeXOrangeOrangeX
5TomatoesTomatoTomatoes
6Apple1
7Tomatoes
8OrangeX
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,215,759
Messages
6,126,728
Members
449,332
Latest member
nokoloina

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