VBA to find a match, preserve the old value in a different cell, and replace matched value with the new value if match found.

BokiRis

New Member
Joined
Sep 8, 2019
Messages
10
I must start off by saying, I have no VBA experience at all so I don’t have a sample VBA code to start from. I am grateful for all of you VBA experts out there and I’m hopeful that someone might be able to help me out.

I’m not sure if this is possible with a single VBA or if it may need to be split up into two separate commands. Either way is fine.

To start with, I have two workbooks. Workbook A (ThisWorkbook), Sheet 27 (OTU), contains two lists. List in Range B:B are the values to be found and matched, list in Range C:C is the replacement values if the match is found. In addition, cell $F$14 contains the directory of the file, cell $F$15 contains the file name, and cell $F$16 contains the Sheet Name of the second workbook.

Second Workbook B(Any name as defined in $F$15 of Workbook A), Sheet 2(Any name as defined in cell $F$16 of Workbook A), contains a list in Range A:A with values to be matched and also a blank range G:G where to preserve the original value from Range A:A.

When comparing the values from Workbook A, Sheet 27, Range B:B with Workbook B, Sheet 2, Range A:A, if match is found, I would like to preserve the original value from the Workbook B, Sheet 2, Range A:A and copy it to a corresponding cell in the same row in Range G:G of Workbook B, Sheet 2. At the same time, I would like to replace the original value in Workbook B, Sheet 2, Range A:A with a replacement value from the Workbook A, Sheet 27, Range C:C, if the match is found.

I would like to use a dynamic option for the Workbook A (ThisWorkbook) so that if the workbook is copied the VBA would still work without having to change the code for every new Workbook A Copy.

Any help is greatly appreciated!!!
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
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