質問編集履歴

2

質問を更新しました。

2021/05/15 22:22

投稿

shogakusha
shogakusha

スコア12

test CHANGED
File without changes
test CHANGED
@@ -6,10 +6,6 @@
6
6
 
7
7
  現在は単一の項目(名字または役職)のみで検索してデータを取得できるのですが、複数項目(名字、名前、役職、入社年月日、退社年月日、SE経験年数、得意言語)を入力した場合でも、合致するデータを取得して転記したいのですが、どのようにすべきでしょうか。
8
8
 
9
- また、列指定(例えば、B列)で検索したい場合は、「sht_shain.Range("B:B").Find(sht_toroku.Range("E3").Value)」
10
-
11
- のような書き方で合っていますでしょうか
12
-
13
9
  乱文で申し訳ございません。
14
10
 
15
11
  アドバイスいただけましたら幸いです。

1

ソースを修正して更新しました。

2021/05/15 22:22

投稿

shogakusha
shogakusha

スコア12

test CHANGED
File without changes
test CHANGED
@@ -126,6 +126,10 @@
126
126
 
127
127
 
128
128
 
129
+ Dim LastRow_shain As Integer
130
+
131
+
132
+
129
133
  Set sht_toroku = Worksheets("社員情報管理_登録")
130
134
 
131
135
  Set sht_shain = Worksheets("社員マスタ")
@@ -134,7 +138,9 @@
134
138
 
135
139
 
136
140
 
137
- sht_itiran.Range("A2:O1000") = ""
141
+ ' sht_itiran.Range("A2:O1000") = ""
142
+
143
+ sht_itiran.Range("A1").CurrentRegion.Offset(1, 0) = ""
138
144
 
139
145
 
140
146
 
@@ -142,15 +148,57 @@
142
148
 
143
149
 
144
150
 
151
+ LastRow_shain = sht_shain.Cells(Rows.Count, 2).End(xlUp).Row
152
+
153
+
154
+
155
+ If sht_toroku.Range("E3") = "" And sht_toroku.Range("J3") = "" And sht_toroku.Range("E5") = "" _
156
+
157
+ And sht_toroku.Range("E7") = "" And sht_toroku.Range("J7") = "" And sht_toroku.Range("M7") = "" _
158
+
159
+ And sht_toroku.Range("E9") = "" And sht_toroku.Range("J9") = "" And sht_toroku.Range("M9") = "" _
160
+
161
+ And sht_toroku.Range("BA11").Value = "0" And sht_toroku.Range("E13") = "" And sht_toroku.Range("J13") = "" _
162
+
163
+ And sht_toroku.Range("O13") = "" And sht_toroku.Range("T13") = "" Then
164
+
165
+
166
+
167
+ sht_shain.Range("A2 : O" & LastRow_shain).Copy
168
+
169
+ sht_itiran.Range("A2").PasteSpecial
170
+
171
+
172
+
173
+ sht_itiran.Activate
174
+
175
+ sht_itiran.Range("A1").Select
176
+
177
+
178
+
179
+ MsgBox "全件のデータを転記しました"
180
+
181
+
182
+
183
+ Exit Sub
184
+
185
+
186
+
187
+ End If
188
+
189
+
190
+
145
191
  '1件目の社員マスタ内のデータを検索
146
192
 
147
193
  If sht_toroku.Range("E3") <> "" Then
148
194
 
149
- Set FoundCell = sht_shain.Range("B:B").Find(sht_toroku.Range("E3").Value)
195
+ ' Set FoundCell = sht_shain.Range("B:B").Find(sht_toroku.Range("E3").Value)
196
+
197
+ Set FoundCell = sht_shain.Range("B2 : B" & LastRow_shain).Find(sht_toroku.Range("E3").Value)
150
198
 
151
199
  ElseIf sht_toroku.Range("E5") <> "" Then
152
200
 
153
- Set FoundCell = sht_shain.Range("D:D").Find(sht_toroku.Range("E5").Value)
201
+ Set FoundCell = sht_shain.Range("D2 : D" & LastRow_shain).Find(sht_toroku.Range("E5").Value)
154
202
 
155
203
  End If
156
204
 
@@ -246,7 +294,37 @@
246
294
 
247
295
 
248
296
 
249
- MsgBox "検索処理が終了し、合致するデータを転記しました"
297
+ MsgBox "検索処理が終了し、合致するデータを転記しました"
298
+
299
+
300
+
301
+
302
+
303
+ ' Else
304
+
305
+ ' Set FirstCell = FoundCell
306
+
307
+ ' FoundCell.Resize(1, 14).Copy sht_itiran.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0)
308
+
309
+ ' End If
310
+
311
+ ' Do
312
+
313
+ ' Set FoundCell = Cells.FindNext(FoundCell)
314
+
315
+ ' If FoundCell.Address = FirstCell.Address Then
316
+
317
+ ' Exit Do
318
+
319
+ ' Else
320
+
321
+ ' FoundCell.Resize(1, 14).Copy sht_itiran.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0)
322
+
323
+ ' End If
324
+
325
+ ' Loop
326
+
327
+
250
328
 
251
329
  End Sub
252
330