公報データの全ての項目を残したまま同じ項目の件数を加算集計する場合には以下のように処理する。
ここでは比較する項目は1列で、加算する件数データは4列目としている。
マクロは次のとおり。
'===============
'同じ項目の件数を加算する
'===============
'A列でソート
Range(Cells(1, 1), Cells(NY2, NX2)).Sort Key1:=Cells(1, 1), Order1:=xlAscending, Header:= _
xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
SortMethod:=xlPinYin
'次行のソートキーが同じならば4列目の件数を加算して当該行を削除
For y = 2 To NY2
If Cells(y, 1) = Cells(y + 1, 1) Then
Cells(y + 1, 4) = Cells(y, 4) + Cells(y + 1, 4)
Rows(y).Clear
End If
Next y
'ソートして空白行を削除
Range(Cells(1, 1), Cells(NY2, NX2)).Sort Key1:=Cells(1, 1), Order1:=xlAscending, Header:= _
xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
SortMethod:=xlPinYin
'