Duplicate Count

B

Brad

I'm writing a macro that will loop through a table of data and count how many
duplicates there are on a given day as defined by user entered range. The
code below works for the 1st date but displays 0 for the remaining dates. Any
help would be appreciated.

Dim enteredDate As Date 'Start Date entered by user
Dim rawDataDate As Date 'Variable date as seen on BAS raw data

' Gets user inputed start date from main page
enteredDate = Workbooks("QDS").Sheets("Sheet1").Cells(5, 3).Value

' Count of days between user selected start and end dates
numDays = Workbooks("QDS").Sheets("Sheet1").Cells(7, 3).Value - _
Workbooks("QDS").Sheets("Sheet1").Cells(5, 3).Value

For i = 1 To numDays
dupecount = 0
Do While Cells(x, 2).Value <> ""
rawDataDate = Cells(x, 12).Value
If Cells(x, 2).Value = Cells(y, 2).Value And DateDiff("d",
rawDataDate,enteredDate) = 0 Then
dupecount = dupecount + 1
End If
x = x + 1
y = y + 1

Loop
Workbooks("QDS").Sheets("Sheet2").Cells(i, 2).Value = dupecount
enteredDate = enteredDate + 1
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top