回答編集履歴

2

追記

2021/02/15 07:54

投稿

jinoji
jinoji

スコア4592

test CHANGED
@@ -77,3 +77,187 @@
77
77
 
78
78
 
79
79
  ```
80
+
81
+ -----
82
+
83
+ <追記>
84
+
85
+ 上記は元のコードをあまり読まずに自分の手癖で書きました。
86
+
87
+ でも、結果的に似たような感じになりましたね。
88
+
89
+ いくつかのスペルミスらしきものを修正してみました。
90
+
91
+
92
+
93
+ ```VBA
94
+
95
+ Sub saiyouritu()
96
+
97
+
98
+
99
+ '=====変数を宣言=====
100
+
101
+ Dim ws1 As Worksheet
102
+
103
+ Dim ws2 As Worksheet
104
+
105
+ Dim Rmax1 As Long
106
+
107
+ Dim Rmax2 As Long
108
+
109
+ Dim dicST_count As Object 'ステータス一覧 件数
110
+
111
+ Dim dicST_row As Object 'ステータス一覧 行番号
112
+
113
+ Dim dicML As Object 'メール一覧
114
+
115
+ Dim dicSY As Object '採用済の一覧
116
+
117
+ Dim dicW As Object 'ステータス作業用
118
+
119
+ Dim wrow As Long
120
+
121
+ Dim key As Variant
122
+
123
+ Dim ArrList As Object 'ArrayList
124
+
125
+ Dim st1 As String
126
+
127
+ Dim st2 As String
128
+
129
+ Dim st As Variant
130
+
131
+
132
+
133
+ '=====定義をセット=====
134
+
135
+ Set dicST_count = CreateObject("Scripting.Dictionary") '連想配列の定義
136
+
137
+ Set dicST_row = CreateObject("Scripting.Dictionary") '連想配列の定義
138
+
139
+ Set dicML = CreateObject("Scripting.Dictionary") '連想配列の定義
140
+
141
+ Set dicSY = CreateObject("Scripting.Dictionary") '連想配列の定義
142
+
143
+ Set ws1 = Sheets("Sheet1")
144
+
145
+ Set ws2 = Sheets("Sheet2")
146
+
147
+
148
+
149
+ '=====最終行を取得=====
150
+
151
+ Rmax1 = ws1.Cells(Rows.Count, "A").End(xlUp).Row 'Sheet1のA列
152
+
153
+ Rmax2 = ws2.Cells(Rows.Count, "A").End(xlUp).Row 'Sheet2のA列
154
+
155
+
156
+
157
+ '=====ステータスの行番号を登録=====
158
+
159
+ For wrow = 2 To Rmax2
160
+
161
+ key = ws2.Cells(wrow, "A")
162
+
163
+ dicST_row(key) = wrow
164
+
165
+ dicST_count(key) = 0
166
+
167
+ Next
168
+
169
+
170
+
171
+ '=====メアド一覧・ステータスを取得======
172
+
173
+ For wrow = 2 To Rmax1
174
+
175
+ key = ws1.Cells(wrow, "A")
176
+
177
+ st1 = ws1.Cells(wrow, "B")
178
+
179
+ st2 = ws1.Cells(wrow, "C")
180
+
181
+ If dicML.Exists(key) = False Then
182
+
183
+ Set ArrList = CreateObject("System.Collections.ArrayList")
184
+
185
+ dicML.Add key, ArrList
186
+
187
+ End If
188
+
189
+
190
+
191
+ dicML(key).Add st1
192
+
193
+ dicML(key).Add st2
194
+
195
+ If st2 = "採用済" Then
196
+
197
+ dicSY(key) = True
198
+
199
+ End If
200
+
201
+ Next
202
+
203
+
204
+
205
+ '=====採用済のメールのみ処理=====
206
+
207
+ For Each key In dicSY
208
+
209
+ Set ArrList = dicML(key)
210
+
211
+ Set dicW = CreateObject("Scripting.Dictionary")
212
+
213
+
214
+
215
+ '=====重複ステータスの削除=====
216
+
217
+ For Each st In ArrList
218
+
219
+ dicW(st) = True
220
+
221
+ Next
222
+
223
+
224
+
225
+ '=====ステータスの加算=====
226
+
227
+ For Each st In dicW
228
+
229
+ If dicST_count.Exists(st) = True Then
230
+
231
+ dicST_count(st) = dicST_count(st) + 1
232
+
233
+ Else
234
+
235
+ MsgBox (st & "はSheet2に登録されていません")
236
+
237
+ Exit Sub
238
+
239
+ End If
240
+
241
+ Next
242
+
243
+ Next
244
+
245
+
246
+
247
+ '=====Sheet2へ書き込み=====
248
+
249
+ For Each key In dicST_count
250
+
251
+ wrow = dicST_row(key)
252
+
253
+ ws2.Cells(wrow, "B") = dicST_count(key)
254
+
255
+ Next
256
+
257
+
258
+
259
+ MsgBox ("完了")
260
+
261
+ End Sub
262
+
263
+ ```

1

修正

2021/02/15 07:54

投稿

jinoji
jinoji

スコア4592

test CHANGED
@@ -46,7 +46,7 @@
46
46
 
47
47
  If c.Offset(, 2).Value = "採用済" Then
48
48
 
49
- For Each v In d(c.Value).Items
49
+ For Each v In d(c.Value).Keys
50
50
 
51
51
  If WorksheetFunction.CountIf(ws2.Columns(1), v) = 0 Then
52
52