keyword
ディクショナリ
入れ子
二重
dictionaryにdictionaryを追加
Sample Code
Sample Code
Public Sub MySample20220520()
Dim arrList As Variant
Dim i As Long: Dim j As Long
Dim myNameList As Dictionary: Dim myTypeList As Dictionary
Dim myName As Variant: Dim myType As Variant
With ThisWorkbook.ActiveSheet
arrList = .Range("A1").CurrentRegion
End With
Set myNameList = New Dictionary
For i = LBound(arrList, 1) + 1 To UBound(arrList, 1)
If Not myNameList.Exists(arrList(i, 1)) Then
Set myTypeList = New Dictionary
myNameList.Add arrList(i, 1), myTypeList
Set myTypeList = myNameList.Item(arrList(i, 1))
myTypeList.Add arrList(i, 2), arrList(i, 3)
Else
If myTypeList Is Nothing Then
Set myTypeList = New Dictionary
End If
Set myTypeList = myNameList.Item(arrList(i, 1))
If myTypeList.Exists(arrList(i, 2)) Then
myTypeList.Item(arrList(i, 2)) = myTypeList.Item(arrList(i, 2)) + arrList(i, 3)
Else
myTypeList.Add arrList(i, 2), arrList(i, 3)
End If
End If
Next i
Set myTypeList = New Dictionary
For Each myName In myNameList.Keys
Set myTypeList = myNameList.Item(myName)
For Each myType In myTypeList.Keys
Debug.Print myName, myType, myTypeList.Item(myType)
Next
Next
End Sub