Find and replace multiple values from a list

ryanpetersen

New Member
Joined
Sep 1, 2014
Messages
5
Hi,


I was wondering if someone could please help me with the following.


I have 'Table' worksheet with sales figures and I'm trying to work out how to make a macro go through a list on the 'Lookup' worksheet, find and replace the values in the 'Table' worksheet.
For example, to search "Product 2" in column A of 'Table' worksheet and replace with "DELETED Product 2" (data from the 'Lookup' worksheet). This would continue until all values have been checked and replaced. Also on the 'Table' worksheet, a product might appear multiple times. For example Product 2 might need to be replaced 3 or 4 times before it starts replacing "Product 4" with "DELETED Product 4"
The end result I'm trying to get to is similar to 'Outcome' below.


Many thanks for your help.

Table
Product 1 $100,000
Product 2 $5,000
Product 3 $120,000
Product 4 $2,000

Lookup
Product 2 = DELETED Product 2
Product 4 = DELETED Product 4

Outcome
Product 1 $100,000
DELETED Product 2 $5,000
Product 3 $120,000
DELETED Product 4 $2,000
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I could figure out how to do this in vba, but I don't want to because of how you formatted the lookup.
Lookup
Product 2 = DELETED Product 2
Product 4 = DELETED Product 4
Does it really look like that? Like does A1 actually say "Product 2 = DELETED Product 2"? It says all of that? Why not just "DELETED Product 2"? If you did it that way, then I could run the REPLACE function to remove DELETED from the string value. Then I could run the TRIM function to get rid of spaces on the ends. Then I could do a wildcard search of "*Product 2*" for every non empty row. If your lookup table really looks like how you described with an equal sign and everything as part of the string, you made it too complicated and I don't want to work around that. I don't think anyone else wants to either or you would have had a reply by now. Can you change the lookup table to something easier? You don't even need to include the word deleted in the value. If the purpose of the lookup table is to log deleted items, then obviously everything in that table is deleted, so why state it in the cell value? All that does is create complication when writing vb code. Simple your dataset up and I could accomplish this in under 30 microts.
 
Upvote 0
Thanks for your reply. I couldn't attach a file so I tried copying the information. Sorry it was unclear.
The data sits in different columns. I've added a comma below for each new column.

Table
Product 1, $100,000
Product 2, $5,000
Product 3, $120,000
Product 4, $2,000

Lookup
Product 2, DELETED Product 2
Product 4, DELETED Product 4

Outcome
Product 1, $100,000
DELETED Product 2, $5,000
Product 3, $120,000
DELETED Product 4, $2,000
 
Upvote 0
A
1product 1
2product 2

<tbody>
</tbody>
In future posts, click on Go Advanced next to the Post Quick Reply button and insert a table.
 
Upvote 0
Alright lets take a look at the Outcome sheet. In cell A1 I want you to enter this formula...
Code:
=IFERROR(VLOOKUP(Table!A1,Lookup!A:B,2,FALSE),Table!A1)


In cell B1 enter this formula...
Code:
=Table!B1


Copy the code down the column. Done. I know you said you wanted VBA, but this was way to easy as a formula.
 
Last edited:
Upvote 0
Thanks for your quick solution WarPiglet.
I'd like to use a macro to apply the change because there are several data sheets (table). Are you able to help with the VBA code please?
 
Upvote 0
Yes I can do it. I'm going to assume you want a subroutine rather than a function? Is this going to be an on change event or at the push of a button?
 
Upvote 0
Taking a bit longer than I hoped. Have to start over. I accidentally created an infinite loop that just crashed my system.
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,435
Members
448,961
Latest member
nzskater

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