お早うございます。
データシートのA列に日付、B列にコード、C列に取扱店数、1行は見出しとして
編集データは「Sheet2」へ展開します。
実行時に、データシートをActiveにしてください。
Type wRec
DATE As String
CODE As String
CNT As Integer
End Type
Dim tTEMPO() As wRec
Dim tTemCnt As Integer
'
Sub 取扱店別日付別合計()
Dim wR As Long
Dim wBuf As Variant
Dim wCd As String
Dim wDt As String
'
Application.ScreenUpdating = False
'コード、日付順にソート
With ActiveSheet
wR = .Range("A" & Rows.Count).End(xlUp).Row
.Range("A1:C" & wR).Sort Key1:=Range("B2"), Order1:=xlAscending, Key2:=Range("A2") _
, Order2:=xlAscending, Header:=xlGuess
wBuf = .Range("A1:C" & wR)
End With
'
Erase tTEMPO: tTemCnt = 0
For wI = 2 To wR
If wCd <> wBuf(wI, 2) Then 'コードチェック
wCd = wBuf(wI, 2)
wDt = ""
End If
If wDt <> wBuf(wI, 1) Then '日付チェック
wDt = wBuf(wI, 1)
tTemCnt = tTemCnt + 1
ReDim Preserve tTEMPO(tTemCnt)
tTEMPO(tTemCnt).DATE = wBuf(wI, 1) '日付設定
tTEMPO(tTemCnt).CODE = wBuf(wI, 2) 'コード設定
End If
tTEMPO(tTemCnt).CNT = tTEMPO(tTemCnt).CNT + wBuf(wI, 3) '取扱店数加算
Next
'
'Sheet2へデータ展開
With Worksheets("Sheet2")
.Cells(1, 1) = "日付"
.Cells(1, 2) = "コード"
.Cells(1, 3) = "取扱店数"
'
For wI = 1 To tTemCnt
.Cells(wI + 1, 1) = tTEMPO(wI).DATE
.Cells(wI + 1, 2) = tTEMPO(wI).CODE
.Cells(wI + 1, 3) = tTEMPO(wI).CNT
Next
End With
Application.ScreenUpdating = True
End Sub