質問編集履歴
2
質問を更新しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
VBAの「検索」ボタン押下で、複数項目を入力した場合でも検索できるようにしたいです。
|
4
4
|
現在は単一の項目(名字または役職)のみで検索してデータを取得できるのですが、複数項目(名字、名前、役職、入社年月日、退社年月日、SE経験年数、得意言語)を入力した場合でも、合致するデータを取得して転記したいのですが、どのようにすべきでしょうか。
|
5
|
-
また、列指定(例えば、B列)で検索したい場合は、「sht_shain.Range("B:B").Find(sht_toroku.Range("E3").Value)」
|
6
|
-
のような書き方で合っていますでしょうか
|
7
5
|
乱文で申し訳ございません。
|
8
6
|
アドバイスいただけましたら幸いです。
|
9
7
|
よろしくお願いいたします。
|
1
ソースを修正して更新しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -62,19 +62,43 @@
|
|
62
62
|
Dim LastRow As Integer
|
63
63
|
Dim FirstCell As Range
|
64
64
|
|
65
|
+
Dim LastRow_shain As Integer
|
66
|
+
|
65
67
|
Set sht_toroku = Worksheets("社員情報管理_登録")
|
66
68
|
Set sht_shain = Worksheets("社員マスタ")
|
67
69
|
Set sht_itiran = Worksheets("社員情報一覧")
|
68
70
|
|
69
|
-
sht_itiran.Range("A2:O1000") = ""
|
71
|
+
' sht_itiran.Range("A2:O1000") = ""
|
72
|
+
sht_itiran.Range("A1").CurrentRegion.Offset(1, 0) = ""
|
70
73
|
|
71
74
|
LastRow = sht_itiran.Cells(Rows.Count, 2).End(xlUp).Row + 1
|
72
75
|
|
76
|
+
LastRow_shain = sht_shain.Cells(Rows.Count, 2).End(xlUp).Row
|
77
|
+
|
78
|
+
If sht_toroku.Range("E3") = "" And sht_toroku.Range("J3") = "" And sht_toroku.Range("E5") = "" _
|
79
|
+
And sht_toroku.Range("E7") = "" And sht_toroku.Range("J7") = "" And sht_toroku.Range("M7") = "" _
|
80
|
+
And sht_toroku.Range("E9") = "" And sht_toroku.Range("J9") = "" And sht_toroku.Range("M9") = "" _
|
81
|
+
And sht_toroku.Range("BA11").Value = "0" And sht_toroku.Range("E13") = "" And sht_toroku.Range("J13") = "" _
|
82
|
+
And sht_toroku.Range("O13") = "" And sht_toroku.Range("T13") = "" Then
|
83
|
+
|
84
|
+
sht_shain.Range("A2 : O" & LastRow_shain).Copy
|
85
|
+
sht_itiran.Range("A2").PasteSpecial
|
86
|
+
|
87
|
+
sht_itiran.Activate
|
88
|
+
sht_itiran.Range("A1").Select
|
89
|
+
|
90
|
+
MsgBox "全件のデータを転記しました"
|
91
|
+
|
92
|
+
Exit Sub
|
93
|
+
|
94
|
+
End If
|
95
|
+
|
73
96
|
'1件目の社員マスタ内のデータを検索
|
74
97
|
If sht_toroku.Range("E3") <> "" Then
|
75
|
-
Set FoundCell = sht_shain.Range("B:B").Find(sht_toroku.Range("E3").Value)
|
98
|
+
' Set FoundCell = sht_shain.Range("B:B").Find(sht_toroku.Range("E3").Value)
|
99
|
+
Set FoundCell = sht_shain.Range("B2 : B" & LastRow_shain).Find(sht_toroku.Range("E3").Value)
|
76
100
|
ElseIf sht_toroku.Range("E5") <> "" Then
|
77
|
-
Set FoundCell = sht_shain.Range("
|
101
|
+
Set FoundCell = sht_shain.Range("D2 : D" & LastRow_shain).Find(sht_toroku.Range("E5").Value)
|
78
102
|
End If
|
79
103
|
|
80
104
|
If sht_toroku.Range("E3") = "" And sht_toroku.Range("E5") = "" Then
|
@@ -122,7 +146,22 @@
|
|
122
146
|
|
123
147
|
sht_itiran.Activate
|
124
148
|
|
125
|
-
MsgBox "検索処理が終了し、合致するデータを転記しました"
|
149
|
+
MsgBox "検索処理が終了し、合致するデータを転記しました"
|
150
|
+
|
151
|
+
|
152
|
+
' Else
|
153
|
+
' Set FirstCell = FoundCell
|
154
|
+
' FoundCell.Resize(1, 14).Copy sht_itiran.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0)
|
155
|
+
' End If
|
156
|
+
' Do
|
157
|
+
' Set FoundCell = Cells.FindNext(FoundCell)
|
158
|
+
' If FoundCell.Address = FirstCell.Address Then
|
159
|
+
' Exit Do
|
160
|
+
' Else
|
161
|
+
' FoundCell.Resize(1, 14).Copy sht_itiran.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0)
|
162
|
+
' End If
|
163
|
+
' Loop
|
164
|
+
|
126
165
|
End Sub
|
127
166
|
|
128
167
|
Sub getShainData(sht_shain As Worksheet, FoundCell As Range)
|