回答編集履歴
2
追記
test
CHANGED
@@ -1,3 +1,65 @@
|
|
1
|
+
実はこんな感じでいけるのかもしれない。
|
2
|
+
|
3
|
+
```VBA
|
4
|
+
|
5
|
+
Sub sample1()
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
'元シートから地域名、地域コードを取得
|
10
|
+
|
11
|
+
Dim ws As Worksheet, rng As Range
|
12
|
+
|
13
|
+
Set ws = Worksheets(1)
|
14
|
+
|
15
|
+
Set rng = ws.Range(ws.Range("A4"), ws.Cells(ws.Rows.Count, 1)).Resize(, 2)
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
'新シートに貼り付け、重複を削除
|
20
|
+
|
21
|
+
Dim newSheet As Worksheet
|
22
|
+
|
23
|
+
Set newSheet = Worksheets.Add(After:=ws)
|
24
|
+
|
25
|
+
rng.Copy Destination:=newSheet.Cells(1, 1)
|
26
|
+
|
27
|
+
newSheet.UsedRange.RemoveDuplicates Columns:=Array(1, 2), Header:=xlNo
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
'地域名ごとに売上金額を合算する数式をセット
|
32
|
+
|
33
|
+
Dim wFormula
|
34
|
+
|
35
|
+
wFormula = Replace("=SUMIF(Sheet1!$A:$A,$A1,Sheet1!D:D)", "Sheet1", ws.Name)
|
36
|
+
|
37
|
+
newSheet.UsedRange.Offset(, 2).Resize(, 13).Formula = wFormula
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
'計算結果を値で再セット
|
42
|
+
|
43
|
+
newSheet.UsedRange.Value = newSheet.UsedRange.Value
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
End Sub
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
```
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
---
|
58
|
+
|
59
|
+
(追記前)
|
60
|
+
|
61
|
+
|
62
|
+
|
1
63
|
```VBA
|
2
64
|
|
3
65
|
Sub sample()
|
1
修正
test
CHANGED
@@ -68,7 +68,7 @@
|
|
68
68
|
|
69
69
|
dicData = areaDic(areaName)
|
70
70
|
|
71
|
-
For i =
|
71
|
+
For i = 3 To UBound(fees)
|
72
72
|
|
73
73
|
fees(i) = fees(i) + dicData(i)
|
74
74
|
|