VBA Counting Unique Values

Flash'

New Member
Joined
May 30, 2013
Messages
10
Morning

Im having trouble counting unique records from my data sheet

on my 'Summary' sheet i have the below.

[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]
B​
[/TD]
[TD]
C​
[/TD]
[TD]
D​
[/TD]
[TD]
E​
[/TD]
[/TR]
[TR]
[TD]
14​
[/TD]
[TD]
Month​
[/TD]
[TD]
Year​
[/TD]
[TD]
Records Uploaded​
[/TD]
[TD]
Unique Records Uploaded​
[/TD]
[/TR]
[TR]
[TD]
15​
[/TD]
[TD]
Oct​
[/TD]
[TD]
15​
[/TD]
[TD]
500​
[/TD]
[TD="align: center"]?
[/TD]
[/TR]
[TR]
[TD]
16​
[/TD]
[TD]
Nov​
[/TD]
[TD]
15​
[/TD]
[TD]
400​
[/TD]
[TD="align: center"]?
[/TD]
[/TR]
</tbody>[/TABLE]

On my 'URData' Sheet i have Columns

[TABLE="width: 500"]
<tbody>[TR]
[TD]
B​
[/TD]
[TD]
Q​
[/TD]
[TD]
R​
[/TD]
[/TR]
[TR]
[TD]
Account Numbers​
[/TD]
[TD]
Month​
[/TD]
[TD]
Year​
[/TD]
[/TR]
[TR]
[TD]467162761[/TD]
[TD]Oct[/TD]
[TD]15[/TD]
[/TR]
[TR]
[TD]156776464[/TD]
[TD]Oct[/TD]
[TD]15[/TD]
[/TR]
</tbody>[/TABLE]


I have used the below code which works great for Counting Records Uploaded on my 'URData' Sheet which meet the criteria (Q =month & R =Year)

Code:
Sub RecordsUploaded()
Dim Month As String
Dim Year As Integer
Dim Answer As Long
Dim i As Long
Dim EnNum As Long
Dim lastrow As Long

'end range of months
EnNum = (Worksheets("Summary").Cells(Rows.Count, "B").End(xlUp).Row) - 14

'Endrange of data
lastrow = Worksheets("URData").Cells(Rows.Count, "A").End(xlUp).Row

For i = 1 To EnNum

Month = Worksheets("Summary").Cells(14 + i, 2).Value
Year = Worksheets("Summary").Cells(14 + i, 3).Value

Answer = WorksheetFunction.CountIfs(Worksheets("URData").Range("Q2: Q" & lastrow), Month, Worksheets("URData").Range("R2: R" & lastrow), Year)
Worksheets("summary").Cells(14 + i, 4).Value = Answer

Next
End Sub

But i need to also count the unique account numbers in column B, with the criteria in Column Q and R

im trying looking all over online but cant seem to be able to find a VBA solution. Any help would be highly appreciated

Thank you
 
Last edited:

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
An Account number could appear twice in one month and once in another month. But i would need it to count as a unique value for both months

[TABLE="class: grid, width: 400, align: center"]
<tbody>[TR]
[TD][/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]Q[/TD]
[TD="align: center"]R[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]129013096[/TD]
[TD="align: center"]Oct[/TD]
[TD="align: center"]15[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: center"]286008162[/TD]
[TD="align: center"]Oct[/TD]
[TD="align: center"]15[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD="align: center"]129013096[/TD]
[TD="align: center"]Oct[/TD]
[TD="align: center"]15[/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD="align: center"]129013096[/TD]
[TD="align: center"]Nov[/TD]
[TD="align: center"]15[/TD]
[/TR]
</tbody>[/TABLE]
Oct 15 - 2 unique
Nov - 1 unique

Hope this makes sense?
 
Upvote 0
ok pivot table looking at account numbers and dates only will list the unique numbers for each month - change your B,Q,R to acnum, monnth, year

and make a pivot - if you have several years data make an additional column called monyr and put in that column = Q1&R1 then pivot on acnum and monyr
 
Upvote 0
Thanks for response all, sorry for bother. but figured it out in the end by creating a unique list first then using a seperate sub

Unable to close this thread, for some reason it does not give me the option. and when clicking on my profile it directs me to another users profile with similer user '<dd class="userprof_module">Flash2002's</dd>'

Admin issue?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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