VBA Duplicate Finding based on date

jr0124

New Member
Joined
Dec 28, 2016
Messages
16
I'm creating a workbook to manage my leads as they come through with some details that'll then trigger to go to a working quote sheet. What I am looking to do is note the duplicate requests that we receive. The way I am hoping I can get it to work is below.
  • Check column C and column E to see if both are duplicates
  • If so, check column A to see if the date is exact
  • If so, in column I type in "Duplicate Request"
Then, I'd like to do another check
  • Check column C and column E to see if both are duplicates
  • If so, check column A to see if the date is within 5 days
  • If so, in column I change the fill of the cell to red
Any ideas?
 

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
Hi ,
In the below statement are we checking whether date is of today ?
  • If so, check column A to see if the date is exact
Thanks,
Saurabh
 
Upvote 0
Hi ,
In the below statement are we checking whether date is of today ?
  • If so, check column A to see if the date is exact
Thanks,
Saurabh
I dont think it'll be today in all cases so let's go with no. More if it matches the other row exactly
 
Upvote 0
Hi,

Check if below code works.

Sheet1 is worksheet name.

VBA Code:
Sub checkDuplicate()
    Dim lastRowColC As Integer, rowno As Integer
    
    lastRowColC = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
    
    For rowno = 1 To lastRowColC
     With Sheets("Sheet1")
        If .Range("C" & rowno) = .Range("E" & rowno) Then
            If Int(.Range("A" & rowno)) = Date Then
                .Range("I" & rowno) = "Duplicate Request"
            ElseIf Date - Int(.Range("A" & rowno)) <= 5 Then
                .Range("I" & rowno).Interior.Color = vbRed
            End If
    
        End If
   End With
Next
 
Upvote 0
This does not require VBA, and in fact I would discourage it for this problem.

I assume that date is "within 5 days" means the one date is ±5 days of the other date.

Use this formula in column I:

Excel Formula:
=IF(COUNTIFS($C:$C,$C2,$E:$E,$E2,$A:$A,$A2)>1,"Duplicate Request","")

Use this conditional formatting rule for column I:

Excel Formula:
=COUNTIFS($C:$C,$C1,$E:$E,$E1,$A:$A,">="&$A1-5,$A:$A,"<="&$A1+5)>1



jr0124=sample.xlsx
ABCDEFGHI
1Some dateSome dataSome other dataFlags
25/26/2021Unique C 1Unique E 1 
35/26/2021Unique C 2Unique E 2 
45/26/2021Unique C 3Unique E 3 
55/26/2021Exact Dupe CExact Dupe EDuplicate Request
65/26/2021Unique C 5Unique E 5 
75/26/2021Unique C 6Unique E 6 
85/26/2021Close In Date CClose In Date E 
95/26/2021Unique C 8Unique E 8 
105/26/2021Unique C 9Unique E 9 
115/26/2021Exact Dupe CExact Dupe EDuplicate Request
125/26/2021Unique C 11Unique E 11 
135/28/2021Close In Date CClose In Date E
145/21/2021Close In Date CClose In Date E
Sheet1
Cell Formulas
RangeFormula
C2:C4,C12,C9:C10,C6:C7C2="Unique C "&ROW()-1
E2:E4,E12,E9:E10,E6:E7E2="Unique E "&ROW()-1
I2:I12I2=IF(COUNTIFS($C:$C,$C2,$E:$E,$E2,$A:$A,$A2)>1,"Duplicate Request","")
Cells with Conditional Formatting
CellConditionCell FormatStop If True
I:IExpression=COUNTIFS($C:$C,$C1,$E:$E,$E1,$A:$A,">="&$A1-5,$A:$A,"<="&$A1+5)>1textNO
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,241
Members
449,075
Latest member
staticfluids

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