回答編集履歴

2

追記

2021/06/05 05:10

投稿

jinoji
jinoji

スコア4592

test CHANGED
@@ -75,3 +75,65 @@
75
75
 
76
76
 
77
77
  ```
78
+
79
+
80
+
81
+ ---
82
+
83
+ もしかして、100Aと100Bは同じ100として合算するのですか。
84
+
85
+
86
+
87
+ ```VBA
88
+
89
+ Sub sample3()
90
+
91
+
92
+
93
+ Dim ws1 As Worksheet
94
+
95
+ Set ws1 = Worksheets(1)
96
+
97
+
98
+
99
+ Dim ws2 As Worksheet
100
+
101
+ Set ws2 = Worksheets.Add(, ws1)
102
+
103
+
104
+
105
+ Dim i, j, k, v
106
+
107
+ For i = 1 To ws1.Cells(ws1.Rows.Count, 1).End(xlUp).Row
108
+
109
+ v = Val(ws1.Cells(i, 1).Value)
110
+
111
+ If WorksheetFunction.CountIf(ws2.Columns(1), v) = 0 Then
112
+
113
+ j = j + 1
114
+
115
+ ws1.Rows(i).Resize(, 5).Copy ws2.Cells(j, 1)
116
+
117
+ ws2.Cells(j, 1).Value = v
118
+
119
+ Else
120
+
121
+ k = WorksheetFunction.Match(v, ws2.Columns(1), False)
122
+
123
+ ws2.Cells(k, 4) = ws2.Cells(k, 4) + ws1.Cells(i, 4)
124
+
125
+ ws2.Cells(k, 5) = ws2.Cells(k, 5) + ws1.Cells(i, 5)
126
+
127
+ End If
128
+
129
+ Next
130
+
131
+
132
+
133
+ End Sub
134
+
135
+
136
+
137
+
138
+
139
+ ```

1

追記

2021/06/05 05:10

投稿

jinoji
jinoji

スコア4592

test CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  ```VBA
8
8
 
9
- Sub sample()
9
+ Sub sample1()
10
10
 
11
11
 
12
12
 
@@ -49,3 +49,29 @@
49
49
  End Sub
50
50
 
51
51
  ```
52
+
53
+
54
+
55
+ ```VBA
56
+
57
+ Sub sample2()
58
+
59
+ Dim rng As Range, ws As Worksheet
60
+
61
+ Set rng = Worksheets(1).UsedRange
62
+
63
+ Set ws = Worksheets.Add(, rng.Worksheet)
64
+
65
+ ws.Range(rng.Address).Value = rng.Value
66
+
67
+ ws.UsedRange.RemoveDuplicates 1
68
+
69
+ 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) & ")"
70
+
71
+ ws.UsedRange.Value = ws.UsedRange.Value
72
+
73
+ End Sub
74
+
75
+
76
+
77
+ ```