回答編集履歴
2
誤字修正
test
CHANGED
@@ -90,7 +90,7 @@
|
|
90
90
|
|
91
91
|
Next i
|
92
92
|
|
93
|
-
Msgb
|
93
|
+
Msgbox a & "の合計: " & total_price
|
94
94
|
|
95
95
|
Next r
|
96
96
|
|
1
コード追記
test
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
どのような結果が欲しいのか不明確です
|
1
|
+
どのような結果が欲しいのか不明確ですが、
|
2
2
|
|
3
|
-
とりあえず
|
4
3
|
|
4
|
+
|
5
|
+
|
6
|
+
|
5
|
-
Sheets(1) の A2:A6 の条件に合致する Worksheets(2)以降のすべてのデータの合計
|
7
|
+
■ Sheets(1) の A2:A6 の条件に合致する Worksheets(2)以降のすべてのデータの合計
|
6
8
|
|
7
9
|
を表示する場合のコード例
|
8
10
|
|
@@ -22,24 +24,76 @@
|
|
22
24
|
|
23
25
|
|
24
26
|
|
27
|
+
Dim i As Long
|
28
|
+
|
25
29
|
For i = 2 To Worksheets.Count
|
26
30
|
|
27
31
|
With Worksheets(i)
|
28
32
|
|
29
|
-
Dim a
|
33
|
+
Dim a As Variant
|
30
34
|
|
31
35
|
For Each a In r
|
32
36
|
|
33
37
|
total_price = total_price + WorksheetFunction.SumIf(.Range("A:A"), a, .Range("B:B"))
|
34
38
|
|
35
|
-
Next
|
39
|
+
Next r
|
36
40
|
|
37
41
|
End With
|
38
42
|
|
39
|
-
Next
|
43
|
+
Next i
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
Msgbox "合計: " & total_price
|
40
48
|
|
41
49
|
End Sub
|
42
50
|
|
51
|
+
```
|
43
52
|
|
44
53
|
|
54
|
+
|
55
|
+
■ Sheets(1) の A2:A6 の各条件毎のWorksheets(2)以降のデータの合計
|
56
|
+
|
57
|
+
を表示する場合のコード例
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
```vba
|
62
|
+
|
63
|
+
Sub total_aggregate()
|
64
|
+
|
65
|
+
Dim total_price As Currency
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
Dim r() As Variant
|
70
|
+
|
71
|
+
r = Worksheets(1).Range("A2:A6").Value '条件を配列に格納
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
Dim a As Variant
|
76
|
+
|
77
|
+
For Each a In r
|
78
|
+
|
79
|
+
total_price = 0
|
80
|
+
|
81
|
+
Dim i As Long
|
82
|
+
|
83
|
+
For i = 2 To Worksheets.Count
|
84
|
+
|
85
|
+
With Worksheets(i)
|
86
|
+
|
87
|
+
total_price = total_price + WorksheetFunction.SumIf(.Range("A:A"), a, .Range("B:B"))
|
88
|
+
|
89
|
+
End With
|
90
|
+
|
91
|
+
Next i
|
92
|
+
|
93
|
+
Msgbpx a & "の合計: " & total_price
|
94
|
+
|
95
|
+
Next r
|
96
|
+
|
97
|
+
End Sub
|
98
|
+
|
45
99
|
```
|