質問編集履歴
5
コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -168,18 +168,7 @@
|
|
168
168
|
Loop
|
169
169
|
|
170
170
|
Close #1
|
171
|
-
|
172
|
-
|
171
|
+
|
173
|
-
'入力CSVを読み込む
|
174
|
-
'ファイル名の可変部分を置換
|
175
|
-
Select Case InVal
|
176
|
-
Case 1
|
177
|
-
'入力シート
|
178
|
-
Open UserForm1.TextBox1.Text For Input As #1
|
179
|
-
Case 4
|
180
|
-
'確認シート
|
181
|
-
Open UserForm4.TextBox1.Text For Input As #1
|
182
|
-
End Select
|
183
172
|
|
184
173
|
wi = 0
|
185
174
|
|
4
コードの編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -75,15 +75,154 @@
|
|
75
75
|
Dim vals As Variant
|
76
76
|
vals = Array(employeeNum, shokusekiTeate, hyoukaKyu)
|
77
77
|
|
78
|
-
'
|
78
|
+
' normalDicに社員番号が存在しない場合、追加
|
79
79
|
If Not normalDic.Exists(employeeNum) Then
|
80
80
|
normalDic.Add employeeNum, vals
|
81
|
-
'
|
81
|
+
' normalDicに社員番号が存在する場合、重複辞書に追加
|
82
82
|
ElseIf normalDic.Exists(employeeNum) And myDic.Exists(employeeNum) = normalDic.Exists(employeeNum) Then
|
83
83
|
myDic.Add employeeNum, vals
|
84
84
|
ElseIf normalDic.Exists(employeeNum) And Not myDic.Exists(employeeNum) Then
|
85
85
|
dupDic.Add employeeNum, employeeNum
|
86
86
|
```
|
87
|
+
### 該当のソースコード(更新)
|
88
|
+
```vba
|
89
|
+
Dim employeeNum, shokusekiTeate, hyoukaKyu, tanjikan As String
|
90
|
+
Dim normalDic, dupDic, myDic As Object
|
91
|
+
Dim vals As Variant
|
92
|
+
|
93
|
+
Set normalDic = CreateObject("Scripting.Dictionary")
|
94
|
+
Set dupDic = CreateObject("Scripting.Dictionary")
|
95
|
+
Set myDic = CreateObject("Scripting.Dictionary")
|
96
|
+
|
97
|
+
'データ行まで読み飛ばし
|
98
|
+
Line Input #1, buf 'ヘッダー行1読込
|
99
|
+
Line Input #1, buf 'ヘッダー行2読込
|
100
|
+
Line Input #1, buf 'ヘッダー行3読込
|
101
|
+
Line Input #1, buf 'カラムID行読込
|
102
|
+
Do Until EOF(1)
|
103
|
+
Line Input #1, buf
|
104
|
+
tmp = Split(buf, ",")
|
105
|
+
|
106
|
+
|
107
|
+
Select Case Val(ArySyoriSet(Pos_SyoriType))
|
108
|
+
Case Inta, Intb
|
109
|
+
employeeNum = tmp(11)
|
110
|
+
teate = tmp(16)
|
111
|
+
|
112
|
+
vals = Array(employeeNum, teate)
|
113
|
+
'normalDicに社員番号が存在しない場合、追加
|
114
|
+
If Not normalDic.Exists(employeeNum) Then
|
115
|
+
normalDic.Add employeeNum, vals
|
116
|
+
Else
|
117
|
+
|
118
|
+
If Not myDic.Exists(employeeNum) Then
|
119
|
+
nvals = normalDic(employeeNum)
|
120
|
+
'normalDicの登録内容と全て一致するなら、追加
|
121
|
+
If vals(0) = nvals(0) And vals(1) = nvals(1) Then
|
122
|
+
myDic.Add employeeNum, vals
|
123
|
+
'dupDicに登録済みなら削除
|
124
|
+
If dupDic.Exists(employeeNum) Then
|
125
|
+
dupDic.Remove employeeNum
|
126
|
+
End If
|
127
|
+
End If
|
128
|
+
End If
|
129
|
+
'dupDic未登録かつmyDic未登録なら、追加
|
130
|
+
If Not dupDic.Exists(employeeNum) Then
|
131
|
+
If Not myDic.Exists(employeeNum) Then
|
132
|
+
dupDic.Add employeeNum, employeeNum
|
133
|
+
End If
|
134
|
+
End If
|
135
|
+
End If
|
136
|
+
|
137
|
+
Case Intc, Intd
|
138
|
+
employeeNum = tmp(11)
|
139
|
+
teate = tmp(45)
|
140
|
+
kyu = tmp(40)
|
141
|
+
|
142
|
+
vals = Array(employeeNum, shokusekiTeate, hyoukaKyu)
|
143
|
+
|
144
|
+
' normalDicに社員番号が存在しない場合、追加
|
145
|
+
If Not normalDic.Exists(employeeNum) Then
|
146
|
+
normalDic.Add employeeNum, vals
|
147
|
+
Else
|
148
|
+
' myDicに社員番号が存在せず、normalDicに社員番号、インフラ手当、給料が同一のデータが登録されていたらmyDicに追加
|
149
|
+
If Not myDic.Exists(employeeNum) Then
|
150
|
+
nvals = normalDic(employeeNum)
|
151
|
+
'normalDicの登録内容と全て一致するなら、追加
|
152
|
+
If vals(0) = nvals(0) And vals(1) = nvals(1) And vals(2) = nvals(2) Then
|
153
|
+
myDic.Add employeeNum, vals
|
154
|
+
'dupDicに登録済みなら削除
|
155
|
+
If dupDic.Exists(employeeNum) Then
|
156
|
+
dupDic.Remove employeeNum
|
157
|
+
End If
|
158
|
+
End If
|
159
|
+
End If
|
160
|
+
'dupDic未登録かつmyDic未登録なら、追加
|
161
|
+
If Not dupDic.Exists(employeeNum) Then
|
162
|
+
If Not myDic.Exists(employeeNum) Then
|
163
|
+
dupDic.Add employeeNum, employeeNum
|
164
|
+
End If
|
165
|
+
End If
|
166
|
+
End If
|
167
|
+
End Select
|
168
|
+
Loop
|
169
|
+
|
170
|
+
Close #1
|
171
|
+
|
172
|
+
'/** 入力CSVファイル読込処理 **/
|
173
|
+
'入力CSVを読み込む
|
174
|
+
'ファイル名の可変部分を置換
|
175
|
+
Select Case InVal
|
176
|
+
Case 1
|
177
|
+
'入力シート
|
178
|
+
Open UserForm1.TextBox1.Text For Input As #1
|
179
|
+
Case 4
|
180
|
+
'確認シート
|
181
|
+
Open UserForm4.TextBox1.Text For Input As #1
|
182
|
+
End Select
|
183
|
+
|
184
|
+
wi = 0
|
185
|
+
|
186
|
+
'データ行まで読み飛ばし
|
187
|
+
Line Input #1, buf 'ヘッダー行1読込
|
188
|
+
Line Input #1, buf 'ヘッダー行2読込
|
189
|
+
Line Input #1, buf 'ヘッダー行3読込
|
190
|
+
Line Input #1, buf 'カラムID行読込
|
191
|
+
Do Until EOF(1) '縦方向ループ
|
192
|
+
Line Input #1, buf '1行読込
|
193
|
+
buf = "," & buf 'ダミー列を追加
|
194
|
+
tmp = Split(buf, ",")
|
195
|
+
|
196
|
+
Select Case Val(ArySyoriSet(Pos_SyoriType))
|
197
|
+
Case Inta, Intb
|
198
|
+
|
199
|
+
employeeNum = tmp(12)
|
200
|
+
teate = tmp(17)
|
201
|
+
tanjikan = tmp(21)
|
202
|
+
|
203
|
+
If (tanjikan = "") And (teate = "") Or (teate = 0) And dupDic.Exists(employeeNum) Then
|
204
|
+
’ご質問の箇所↓
|
205
|
+
If Not myDic.Exists(employeeNum) Then
|
206
|
+
GoTo Continue
|
207
|
+
End If
|
208
|
+
End If
|
209
|
+
|
210
|
+
Case Intc, Intd
|
211
|
+
employeeNum = tmp(12)
|
212
|
+
teate = tmp(46)
|
213
|
+
kyu = tmp(41)
|
214
|
+
tanjikan = tmp(20)
|
215
|
+
|
216
|
+
' インフラ手当が空白で、かつ社員番号が重複している場合、レコードをスキップする
|
217
|
+
If (teate = "") Or (teate = 0) And (kyu = "") Or (kyu = 0) And dupDic.Exists(employeeNum) Then
|
218
|
+
GoTo Continue
|
219
|
+
ElseIf (teate = "") Or (teate = 0) And dupDic.Exists(employeeNum) And (tanjikan = "") Then
|
220
|
+
GoTo Continue
|
221
|
+
End If
|
222
|
+
End Select
|
223
|
+
|
224
|
+
|
225
|
+
|
87
226
|
|
88
227
|
### 試したこと
|
89
228
|
|
3
コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -61,6 +61,28 @@
|
|
61
61
|
|
62
62
|
Close #1
|
63
63
|
|
64
|
+
|
65
|
+
|
66
|
+
```
|
67
|
+
|
68
|
+
### 該当のソースコードver2(修正後)
|
69
|
+
下記コードは、正常終了していますが、実現したいことに記載のある通りには機能しませんでした。
|
70
|
+
|
71
|
+
```vba
|
72
|
+
employeeNum = tmp(11)
|
73
|
+
teate = tmp(45)
|
74
|
+
kyu = tmp(40)
|
75
|
+
Dim vals As Variant
|
76
|
+
vals = Array(employeeNum, shokusekiTeate, hyoukaKyu)
|
77
|
+
|
78
|
+
' 正常辞書に社員番号が存在しない場合、追加
|
79
|
+
If Not normalDic.Exists(employeeNum) Then
|
80
|
+
normalDic.Add employeeNum, vals
|
81
|
+
' 正常辞書に社員番号が存在する場合、重複辞書に追加
|
82
|
+
ElseIf normalDic.Exists(employeeNum) And myDic.Exists(employeeNum) = normalDic.Exists(employeeNum) Then
|
83
|
+
myDic.Add employeeNum, vals
|
84
|
+
ElseIf normalDic.Exists(employeeNum) And Not myDic.Exists(employeeNum) Then
|
85
|
+
dupDic.Add employeeNum, employeeNum
|
64
86
|
```
|
65
87
|
|
66
88
|
### 試したこと
|
2
説明補足
test
CHANGED
File without changes
|
test
CHANGED
@@ -11,6 +11,7 @@
|
|
11
11
|
dupDicは、今回のソースコードに記載のemployeeNumのみを見て、normalDicにすでに格納されていれば、重複と認識し、myDicに格納する
|
12
12
|
|
13
13
|
★myDicではじかれた重複の人は、dupDicに格納したくないです
|
14
|
+
⇒myDicの内容は、削除処理をいれても問題ないです
|
14
15
|
|
15
16
|
|
16
17
|
### 発生している問題・エラーメッセージ
|
1
内容補足
test
CHANGED
File without changes
|
test
CHANGED
@@ -9,7 +9,8 @@
|
|
9
9
|
myDicは、今回のソースコードに記載のvalsを見て、normalDicにすでに格納されていれば、重複と認識し、myDicに格納する
|
10
10
|
|
11
11
|
dupDicは、今回のソースコードに記載のemployeeNumのみを見て、normalDicにすでに格納されていれば、重複と認識し、myDicに格納する
|
12
|
+
|
12
|
-
|
13
|
+
★myDicではじかれた重複の人は、dupDicに格納したくないです
|
13
14
|
|
14
15
|
|
15
16
|
### 発生している問題・エラーメッセージ
|