Check duplicates in one column based on duplicates in another column and assign a value based on a condition.

floydschoice

New Member
Joined
Mar 30, 2020
Messages
5
Office Version
  1. 2013
  2. 2011
Platform
  1. Windows
I have a few columns and couple thousand rows.
NameLocationStatusAction
JakeGermanyoutRetain
JakeEthiopiaoutDelete
JakeGermanyinRetain
JakeGermanyoutRetain
JakeEthiopiaoutDelete

In the above table, if Jake is "in" (3rd column) "Germany" (just an example of country) even once, then there should be "Retain" in the 4th column for each of the times Jake has been to Germany "in" and "out".
However, if Jake has been to Ethiopia and has no "in" entry for any of his travels to Ethiopia, then there should be a "Delete" in the 4th column for each of the times Jake has been to Ethiopia. I am relatively new to VBA and I have no idea how to make this work. Can someone help?

PS. The name and the countries mentioned are only example. There could n number of different names and countries in the sheet.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hi & welcome to MrExcel.
You can do that very simply with a formula like this

+Fluff.xlsm
ABCD
1NameLocationStatusAction
2JakeGermanyoutRetain
3JakeEthiopiaoutDelete
4JakeGermanyinRetain
5JakeGermanyoutRetain
6JakeEthiopiaoutDelete
7BobUKinRetain
8BobFranceoutDelete
9BobGermanyoutDelete
10BobEthiopiainRetain
11BobGermanyoutDelete
12BobEthiopiaoutRetain
13BobUKoutRetain
Report
Cell Formulas
RangeFormula
D2:D13D2=IF(COUNTIFS(A:A,A2,B:B,B2,C:C,"In")>0,"Retain","Delete")
 
Upvote 0
Hi Fluff, this worked perfectly well. I did have a problem embedding this formula in the VBA code but I worked it out.
Hi & welcome to MrExcel.
You can do that very simply with a formula like this

+Fluff.xlsm
ABCD
1NameLocationStatusAction
2JakeGermanyoutRetain
3JakeEthiopiaoutDelete
4JakeGermanyinRetain
5JakeGermanyoutRetain
6JakeEthiopiaoutDelete
7BobUKinRetain
8BobFranceoutDelete
9BobGermanyoutDelete
10BobEthiopiainRetain
11BobGermanyoutDelete
12BobEthiopiaoutRetain
13BobUKoutRetain
Report
Cell Formulas
RangeFormula
D2:D13D2=IF(COUNTIFS(A:A,A2,B:B,B2,C:C,"In")>0,"Retain","Delete")

This worked perfectly well although initially I had problems embedding this in my VBA code but I figured it out. Thanks a lot for your help.
 
Upvote 0
Glad it helped & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,812
Messages
6,121,704
Members
449,048
Latest member
81jamesacct

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