HockeyGuy4433
New Member
- Joined
- Jun 20, 2018
- Messages
- 6
Hi everyone,
I'm trying to count the unique number of entries in column A (A2:A16050) in my worksheet titled "RawData". The sheet contains info on the number of accidents involving vehicles, so sometimes an accident can have 2-6 vehicles involved meaning the accident ID will occur repeatedly in column A. The answer will appear in my worksheet titled "Questions" in C5.
Simply put, I'm trying to count the number of occurrences involving more than a single vehicle.
Here is the closest I've come:
Sub CountUnique()
' Number of occurrences involving more than a single vehicle
' Variable declarations
Dim d As Object
Dim c As Variant
Dim i As Long
Dim LastRow As Long
Dim j, count, num, flag, OccNo As String
' Range & clear answer cell
LastRow = Worksheets("RawData").Cells(Rows.count, "A").End(xlUp).Row
Worksheets("Questions").Range("C5").Clear
' Start of code written to count occurrences involving more than a single vehicle
' loop
count = 1
Set d = CreateObject("Scripting.Dictionary")
c = Range("A2:A" & LastRow)
For i = 2 To UBound(c, 1)
d(c(i, 1)) = 1
Next i
Range("B2").Resize(d.count) = Application.Transpose(d.keys)
' Location of answer
Worksheets("Questions").Cells(5, "C") = count
End Sub
I'm trying to count the unique number of entries in column A (A2:A16050) in my worksheet titled "RawData". The sheet contains info on the number of accidents involving vehicles, so sometimes an accident can have 2-6 vehicles involved meaning the accident ID will occur repeatedly in column A. The answer will appear in my worksheet titled "Questions" in C5.
Simply put, I'm trying to count the number of occurrences involving more than a single vehicle.
Here is the closest I've come:
Sub CountUnique()
' Number of occurrences involving more than a single vehicle
' Variable declarations
Dim d As Object
Dim c As Variant
Dim i As Long
Dim LastRow As Long
Dim j, count, num, flag, OccNo As String
' Range & clear answer cell
LastRow = Worksheets("RawData").Cells(Rows.count, "A").End(xlUp).Row
Worksheets("Questions").Range("C5").Clear
' Start of code written to count occurrences involving more than a single vehicle
' loop
count = 1
Set d = CreateObject("Scripting.Dictionary")
c = Range("A2:A" & LastRow)
For i = 2 To UBound(c, 1)
d(c(i, 1)) = 1
Next i
Range("B2").Resize(d.count) = Application.Transpose(d.keys)
' Location of answer
Worksheets("Questions").Cells(5, "C") = count
End Sub