回答編集履歴
2
もう少し改善できる点があったので補足
answer
CHANGED
@@ -112,4 +112,38 @@
|
|
112
112
|
|
113
113
|
Arry.Add list, Array(.Cells(j, "Y"), .Cells(j, "Z"), .Cells(j, "AA"), .Cells(j, "AB"))
|
114
114
|
|
115
|
-
の記述ミスですよね。
|
115
|
+
の記述ミスですよね。
|
116
|
+
|
117
|
+
(4)
|
118
|
+
Arry.Add list, Array(.Cells(j, "Y"), .Cells(j, "Z"), .Cells(j, "AA"), .Cells(j, "AB"))
|
119
|
+
|
120
|
+
とありましたがよく見ると連続するセルですね。
|
121
|
+
この為
|
122
|
+
|
123
|
+
Arry.Add list, .Range("Y" & j & ":AB" & j).value
|
124
|
+
|
125
|
+
とした方が若干早いかもですね。
|
126
|
+
こちらの場合にすると処理の書き方が変わるので変えた内容も記載しておきます。
|
127
|
+
|
128
|
+
```VBA
|
129
|
+
With ws2
|
130
|
+
For j = 2 To lRow2
|
131
|
+
list = .Cells(j, "G") & .Cells(j, "W")
|
132
|
+
Arry.Add list, .Range("Y" & j & ":AB" & j).Value
|
133
|
+
Next j
|
134
|
+
End With
|
135
|
+
|
136
|
+
Dim str, aKey, aItem
|
137
|
+
|
138
|
+
With ws1
|
139
|
+
Dim tV As Variant
|
140
|
+
ReDim tV(3 To lRow1, 0)
|
141
|
+
For k = 3 To lRow1
|
142
|
+
str = .Cells(k, "B") & .Cells(k, "C")
|
143
|
+
If Arry.Exists(str) Then
|
144
|
+
tV(k, 0) = Arry.Item(str)(1, 1)
|
145
|
+
End If
|
146
|
+
Next k
|
147
|
+
.Range("E3:E" & lRow1).Value = tV
|
148
|
+
End With
|
149
|
+
```
|
1
辞書の値が配列である点の考慮が漏れていたので修正
answer
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
|
3
3
|
```VBA
|
4
4
|
|
5
|
-
|
5
|
+
Arry.Add list, Array(.Cells(j, "Y"), .Cells(j, "Z"), .Cells(j, "AA"), .Cells(j, "AB"))
|
6
6
|
|
7
7
|
```
|
8
8
|
ですが,これだとRangeオブジェクトのまま操作していることになります。
|
9
9
|
|
10
10
|
```VBA
|
11
11
|
|
12
|
-
|
12
|
+
Arry.Add list, Array(.Cells(j, "Y").value, .Cells(j, "Z").value, .Cells(j, "AA").value, .Cells(j, "AB").value)
|
13
13
|
|
14
14
|
```
|
15
15
|
とすることで値での処理になります。
|
@@ -46,7 +46,7 @@
|
|
46
46
|
For k = 3 To lRow1
|
47
47
|
str = .Cells(k, "B") & .Cells(k, "C")
|
48
48
|
If Arry.Exists(str) Then
|
49
|
-
.Cells(k, "E") = Arry.Item(str)
|
49
|
+
.Cells(k, "E") = Arry.Item(str)(0)
|
50
50
|
End If
|
51
51
|
Next k
|
52
52
|
End With
|
@@ -63,7 +63,7 @@
|
|
63
63
|
For k = 3 To lRow1
|
64
64
|
str = .Cells(k, "B") & .Cells(k, "C")
|
65
65
|
If Arry.Exists(str) Then
|
66
|
-
tV(k,0) = Arry.Item(str)
|
66
|
+
tV(k,0) = Arry.Item(str)(0)
|
67
67
|
End If
|
68
68
|
Next k
|
69
69
|
.Range("E3:E" & lRow1).Value = tV
|
@@ -80,7 +80,7 @@
|
|
80
80
|
For k = 3 To lRow1
|
81
81
|
str = .Cells(k, "B") & .Cells(k, "C")
|
82
82
|
If Arry.Exists(str) Then
|
83
|
-
tV(k - 2, 1) = Arry.Item(str)
|
83
|
+
tV(k - 2, 1) = Arry.Item(str)(0)
|
84
84
|
End If
|
85
85
|
Next k
|
86
86
|
.Range("E3:E" & lRow1).Value = tV
|
@@ -92,6 +92,24 @@
|
|
92
92
|
|
93
93
|
以上で、処理速度に関しては、早くなるかと思います。
|
94
94
|
|
95
|
+
(補足)
|
96
|
+
(1)
|
95
|
-
|
97
|
+
処理速度とは関係ありませんが
|
96
98
|
Dim str
|
97
|
-
というのは、str関数を上書きしてしまう(str関数が使いにくくなる)ので使わない方が良いと思います。
|
99
|
+
というのは、str関数を上書きしてしまう(str関数が使いにくくなる)ので使わない方が良いと思います。
|
100
|
+
|
101
|
+
(2)
|
102
|
+
Arryの値を配列で持っていますが一つ目の値しか使っていないですよね。
|
103
|
+
これは、想定通りなのでしょうか。
|
104
|
+
想定通りであるのであれば、良いのですが。
|
105
|
+
|
106
|
+
(3)
|
107
|
+
質問文では
|
108
|
+
|
109
|
+
ARY.Add list, Array(.Cells(j, "Y"), .Cells(j, "Z"), .Cells(j, "AA"), .Cells(j, "AB"))
|
110
|
+
|
111
|
+
となってますが
|
112
|
+
|
113
|
+
Arry.Add list, Array(.Cells(j, "Y"), .Cells(j, "Z"), .Cells(j, "AA"), .Cells(j, "AB"))
|
114
|
+
|
115
|
+
の記述ミスですよね。
|