ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Duplicate Count (https://www.excelbanter.com/excel-programming/418496-duplicate-count.html)

Brad

Duplicate Count
 
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


Bernd P

Duplicate Count
 
Hello,

Maybe my UDF lfreq can serve as an example for you:
http://www.sulprobil.com/html/listfreq.html

Regards,
Bernd


All times are GMT +1. The time now is 12:53 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com