Hi, I would like to populate my listbox1 with values from a worksheet called "Summary"
The listbox result should be:
1st column: Unique Payee names
2nd column: sum of their gross
3rd column: sum of their tax
4th column: sum of their net
Payee |
Gross |
Tax |
Net |
Person1 |
10,000 |
3,000 |
7,000 |
Person2 |
1,500 |
500 |
1,000 |
Person1 |
2,000 |
300 |
1,700 |
Person2 |
5,000 |
1,000 |
4,000 |
Tried:
Dim rng As Range, dn As Range, q As Variant, dic As Object
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Summary")
Set rng = ws.Range(ws.Range("E7"), ws.Range("E" & Rows.Count).End(xlUp)) 'Actual data starts from row 7
Set dic = CreateObject("Scripting.Dictionary")
dic.CompareMode = vbTextCompare
For Each dn In rng
If Not dic.Exists(dn.value) Then
dic.Add dn.value, Array(dn.value, dn.Offset(, 1).value, dn.Offset(, 2).value)
Else
q = dic(dn.value)
q(1) = q(2) + dn.Offset(, 2).value
q(2) = q(2) + dn.Offset(, 2).value
'q(3) = q(3) + dn.Offset(, 3).value
dic(dn.value) = q
End If
Next
With Me.ListBox1
.ColumnCount = 4
.ColumnWidths = "100,100,100, 100"
.List = Application.Index(dic.items, 0, 0)
End With
Since I only got these codes from somewhere else, I tried messing around with the values inside the q() but I can't seem to get the right column offset.
Bookmarks