もしかすると、メニューから「おすすめピボットテーブル」あたりの機能でポチポチやった方が
早く目的のものが得られるのかもしれませんが、マクロで作るなら例えばこんな感じでしょうか。
VBA
1Sub sample1()
2
3 Dim ws1 As Worksheet
4 Set ws1 = Worksheets(1)
5
6 Dim ws2 As Worksheet
7 Set ws2 = Worksheets.Add(, ws1)
8
9 Dim i, j, k
10 For i = 1 To ws1.Cells(ws1.Rows.Count, 1).End(xlUp).Row
11 If WorksheetFunction.CountIf(ws2.Columns(1), ws1.Cells(i, 1)) = 0 Then
12 j = j + 1
13 ws1.Rows(i).Resize(, 5).Copy ws2.Cells(j, 1)
14 Else
15 k = WorksheetFunction.Match(ws1.Cells(i, 1), ws2.Columns(1), False)
16 ws2.Cells(k, 4) = ws2.Cells(k, 4) + ws1.Cells(i, 4)
17 ws2.Cells(k, 5) = ws2.Cells(k, 5) + ws1.Cells(i, 5)
18 End If
19 Next
20
21End Sub
VBA
1Sub sample2()
2 Dim rng As Range, ws As Worksheet
3 Set rng = Worksheets(1).UsedRange
4 Set ws = Worksheets.Add(, rng.Worksheet)
5 ws.Range(rng.Address).Value = rng.Value
6 ws.UsedRange.RemoveDuplicates 1
7 ws.UsedRange.Columns(4).Resize(, 2).Formula = "=SUMIF(" & rng.Columns(1).Address(True, True, , True) & "," & ws.Cells(1, 1).Address(False, True, , True) & "," & rng.Columns(4).Address(True, False, , True) & ")"
8 ws.UsedRange.Value = ws.UsedRange.Value
9End Sub
10
もしかして、100Aと100Bは同じ100として合算するのですか。
VBA
1Sub sample3()
2
3 Dim ws1 As Worksheet
4 Set ws1 = Worksheets(1)
5
6 Dim ws2 As Worksheet
7 Set ws2 = Worksheets.Add(, ws1)
8
9 Dim i, j, k, v
10 For i = 1 To ws1.Cells(ws1.Rows.Count, 1).End(xlUp).Row
11 v = Val(ws1.Cells(i, 1).Value)
12 If WorksheetFunction.CountIf(ws2.Columns(1), v) = 0 Then
13 j = j + 1
14 ws1.Rows(i).Resize(, 5).Copy ws2.Cells(j, 1)
15 ws2.Cells(j, 1).Value = v
16 Else
17 k = WorksheetFunction.Match(v, ws2.Columns(1), False)
18 ws2.Cells(k, 4) = ws2.Cells(k, 4) + ws1.Cells(i, 4)
19 ws2.Cells(k, 5) = ws2.Cells(k, 5) + ws1.Cells(i, 5)
20 End If
21 Next
22
23End Sub
24
25