Sub 連想配列SUMIF()
'************事前準備*******************
'参照設定:Microsoft Scripting Runtime
'***************************************
'***************************************
'集計シート、データシートの設定
'***************************************
Dim XX As Long, YY As Long
Set Smg = Sheets("Sheet2")
Set Myedge = Sheets("Sheet1")
XX = Smg.Cells(Rows.Count, 1).End(xlUp).Row
YY = Myedge.Cells(Rows.Count, 1).End(xlUp).Row
'***************************************
'データシート全体を連想配列Dictionaryを使って処理
'***************************************
'参照設定:Microsoft Scripting Runtime を設定しない場合は右コメントに変更
Dim Dicedge As Dictionary 'Dim Dicedge As Object
Set Dicedge = New Dictionary 'Set Dicedge = CreateObject("Scripting.Dictionary")
Dim Edgekey As String
Dim Edgesuu As Long
Dim AA As Long, BB As Long
For BB = 2 To YY
Edgekey = Myedge.Cells(BB, 1)
Edgesuu = Myedge.Cells(BB, 4)
If Dicedge.Exists(Edgekey) Then
Dicedge(Edgekey) = Dicedge(Edgekey) + Edgesuu
Else
Dicedge.Add Edgekey, Edgesuu
End If
Next BB
'***************************************
'集計シートに結果を転記
'***************************************
Dim Targetkey As String
For AA = 11 To XX
Targetkey = Smg.Cells(AA, 1).Value
If Dicedge.Exists(Targetkey) Then
Smg.Cells(AA, 8) = Dicedge(Targetkey)
Else
Smg.Cells(AA, 8) = ""
End If
Next AA
End Sub