|
こんばんは
sheet1のものをsheet2に集計します。
Sub 集計()
Dim sh1 As Worksheet
Dim sh2 As Worksheet
Dim dicA As Object
Dim dicB As Object
Dim dicC As Object
Dim vntA, vntB
Dim i As Long, j As Long
Set sh1 = Worksheets("Sheet1")
Set sh2 = Worksheets("Sheet2")
Set dicA = CreateObject("Scripting.Dictionary")
Set dicB = CreateObject("Scripting.Dictionary")
Set dicC = CreateObject("Scripting.Dictionary")
vntA = sh1.Range("A2", sh1.Range("B65536").End(xlUp)).Value
For i = 1 To UBound(vntA)
dicA(vntA(i, 1) & vntA(i, 2)) = dicA(vntA(i, 1) & vntA(i, 2)) + 1
dicB(vntA(i, 1)) = Empty
dicC(vntA(i, 2)) = Empty
Next i
sh2.Range("A2").Resize(dicB.Count).Value = Application.Transpose(dicB.keys())
sh2.Range("B1").Resize(, dicC.Count).Value = dicC.keys()
vntB = sh2.Range("A1").CurrentRegion.Value
For i = 2 To UBound(vntB)
For j = 2 To dicC.Count + 1
vntB(i, j) = dicA(vntB(i, 1) & vntB(1, j))
Next
Next i
sh2.Range("A1").CurrentRegion.Value = vntB
Set sh1 = Nothing
Set sh2 = Nothing
Set dicA = Nothing
Set dicB = Nothing
Set dicC = Nothing
|
|