|
▼よぽん さん:
力技です。
Sub Test()
Dim sl As Object
Dim v As Variant
Dim dic As Object
Dim r As Range
Dim col As Range
Dim c As Range
Dim x As Long
Dim i As Long
Set dic = CreateObject("Scripting.Dictionary")
Set sl = CreateObject("System.Collections.SortedList")
For Each c In Range("K1").CurrentRegion.Columns(1).Cells
dic(c.Value) = 0
Next
Set r = Range("A1", ActiveSheet.UsedRange).Columns("A:F")
x = r.Columns.Count
For i = 1 To x Step 2
For Each col In r.Columns(i)
For Each c In col.Cells
If Not IsEmpty(c.Value) Then
sl(c.Value) = sl(c.Value) + c.Offset(, 1).Value
If dic.exists(c.Value) Then dic(c.Value) = dic(c.Value) + c.Offset(, 1).Value
End If
Next
Next
Next
ReDim v(0 To sl.Count, 0 To 1)
For i = 0 To sl.Count - 1
v(i, 0) = sl.getkey(i)
v(i, 1) = sl.getbyindex(i)
Next
Range("H1").CurrentRegion.ClearContents
Range("H1").Resize(sl.Count, 2).Value = v
v = dic.items
Range("L1").Resize(dic.Count).Value = WorksheetFunction.Transpose(dic.items)
End Sub
|
|