Excel macro for 'find and replace' values loop

StandardDeviation

New Member
Joined
Feb 7, 2017
Messages
1
Hi,

I have an Excel doc containing a table with 4 columns - Contact Name, Contact Company, Contact Job Title, Owner. The Owner column (col. D), displays the names of any and all company personnel (past and present) who know that particular contact. If there are multiple Owners, each name is separated by a semi-colon - see Table 1 below.

Tab 2 contains a list of names consisting of former company personnel - see Table 2 below.

I need a code to remove the names of former company personnel found within the Owner column. Starting with D2, the macro would compare the names in this cell with all of the names in Tab 2 and remove any matching ones. In effect, the "replace" value is a blank. Then it needs to perform the same operation for cells D3, D4, and so on - see Result table below.


Table 1 (on tab 1)
Name
Company
Job Title
Owner
John Green
ABC Inc
Accounting
Lincoln, Abraham; Day, Doris; Brock, Isaac; Cruz, Penelope
Frieda Kahlo
XYZ Inc
HR
Craig, Daniel; Houdini, Harry; Cruz, Penelope
Geddy Lee
PPP Inc
Operations
Wyle, Noah; Lincoln, Abraham; Martin, Dean

<tbody>
</tbody>

Table 2 (on tab 2)
Former Company Personnel
Lincoln, Abraham
Martin, Chris
Cruz, Penelope
Armstrong, Louis

<tbody>
</tbody>


Result Table
Name
Company
Job Title
User
John Green
ABC Inc
Accounting
Day, Doris; Brock, Isaac;
Frieda Kahlo
XYZ Inc
HR
Craig, Daniel; Houdini, Harry;
Geddy Lee
PPP Inc
Operations
Wyle, Noah; Martin, Dean

<tbody>
</tbody>


Your help is much appreciated! Thanks.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
try this

i'm assuming all information is on the same sheet

Code:
Sub ReplaceOwners()


Dim rngTable2 As Range
Dim rngOwner As Range
Dim cell As Range


Set rngTable2 = Range("F2:F5")  'adjust the range to your case
Set rngOwner = Range("D2:D5")   'adjust the range to your case


For Each cell In rngTable2
    rngOwner.Replace cell.Value & "; ", ""
Next cell


End Sub
 
Upvote 0

Forum statistics

Threads
1,215,053
Messages
6,122,888
Members
449,097
Latest member
dbomb1414

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