anthonyexcel
Active Member
- Joined
- Jun 10, 2011
- Messages
- 258
- Office Version
- 365
- Platform
- Windows
I am working with dictionaries and am very new to them. I have a small sample below. What I am trying to do is to have a unique list with the number of times SICK occurs. I am able to accomplish this but then I would also like to bring back the first and last name which I am having a problem with. I want
<tbody>
</tbody>
But I get this
<tbody>
</tbody>
This is the sample data set
<style type="text/css">
table.tableizer-table {
font-size: 12px;
border: 1px solid #CCC;
font-family: Arial, Helvetica, sans-serif;
}
.tableizer-table td {
padding: 4px;
margin: 3px;
border: 1px solid #CCC;
}
.tableizer-table th {
background-color: #104E8B;
color: #FFF;
font-weight: bold;
}
</style>
<tbody>
</tbody>
Thanks in advance
ID | Count | First | Last |
---|---|---|---|
10878 | 5 | George | Washington |
<tbody>
</tbody>
But I get this
ID | Count |
---|---|
10878 | 5 |
<tbody>
</tbody>
This is the sample data set
<style type="text/css">
table.tableizer-table {
font-size: 12px;
border: 1px solid #CCC;
font-family: Arial, Helvetica, sans-serif;
}
.tableizer-table td {
padding: 4px;
margin: 3px;
border: 1px solid #CCC;
}
.tableizer-table th {
background-color: #104E8B;
color: #FFF;
font-weight: bold;
}
</style>
Emp# | FirstName | LastName | Accrual Description |
---|---|---|---|
10878 | George | Washington | VACATION |
10878 | George | Washington | VACATION |
10878 | George | Washington | VACATION |
10878 | George | Washington | VACATION |
10878 | George | Washington | VACATION |
10878 | George | Washington | VACATION |
10878 | George | Washington | VACATION |
10878 | George | Washington | VACATION |
10878 | George | Washington | VACATION |
10878 | George | Washington | VACATION |
10878 | George | Washington | VACATION |
10878 | George | Washington | VACATION |
10878 | George | Washington | SICK |
10878 | George | Washington | SICK |
10878 | George | Washington | SICK |
10878 | George | Washington | SICK |
10878 | George | Washington | SICK |
10878 | George | Washington | PERSONAL |
10878 | George | Washington | PERSONAL |
10878 | George | Washington | PERSONAL |
10878 | George | Washington | PERSONAL |
10878 | George | Washington | PERSONAL |
11768 | AL | Gore | VACATION |
11768 | AL | Gore | VACATION |
11768 | AL | Gore | SICK |
11768 | AL | Gore | SICK |
11768 | AL | Gore | SICK |
11768 | AL | Gore | SICK |
11768 | AL | Gore | SICK |
11768 | AL | Gore | SICK |
11768 | AL | Gore | PERSONAL |
11768 | AL | Gore | PERSONAL |
11768 | AL | Gore | PERSONAL |
11768 | AL | Gore | PERSONAL |
<tbody>
</tbody>
Code:
Sub Countit()
Dim lastrow As Long
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Dim dic As New Dictionary
For Each cell In Range("A2:A" & lastrow)
If cell.Offset(0, 3) = "SICK" Then
If Not dic.Exists(cell.Value) Then
dic.Add cell.Value, WorksheetFunction.CountA(cell.Value)
Else
dic.Item(cell.Value) = dic.Item(cell.Value) + WorksheetFunction.CountA(cell.Value)
End If
End If
Next
Range("P1") = "ID"
Range("Q1") = "Count"
Range("Q2").Resize(dic.Count, 1).Value = WorksheetFunction.Transpose(dic.Items)
Range("P2").Resize(dic.Count, 1).Value = WorksheetFunction.Transpose(dic.Keys)
End Sub
Thanks in advance