1
if文と.autofilterを使って、読んでいるテキストファイルの最初の2桁が何であるかによって異なる列で検索します。私の問題は、テキストファイルの最初の行の対応する列を検索し、ループを実行するたびに同じ列を検索することです。これは私が持っているものです:オートフィルタエラー(間違った列にある)
Dim myFile As String
myFile = Application.GetOpenFilename()
Open myFile For Input As #1
Dim source As String
Dim destination As Range
Dim rowNum As Long
Set destination = Sheets("SHOULDER").Range("A2")
Do Until EOF(1)
Line Input #1, source
If Mid(source, 1, 2) = "09" Then
With destination.Columns("B:C")
.AutoFilter field:=1, Criteria1:=Mid(source, 3, 4)
.AutoFilter field:=2, Criteria1:=Mid(source, 7, 4)
End With
rowNum = Range("A" & Rows.Count).End(xlUp).row
Cells(rowNum, 8).Value = Mid(source, 23, 2) & " " & Mid(source, 21, 2) & " " & Mid(source, 19, 2)
Cells(rowNum, 9).Value = Mid(source, 11, 2) & "/" & Mid(source, 13, 2) & "/" & Mid(source, 15, 4)
ElseIf Mid(source, 1, 2) = "15" Then
With destination.Columns("L:M")
.AutoFilter field:=1, Criteria1:=Mid(source, 3, 4)
.AutoFilter field:=2, Criteria1:=Mid(source, 7, 4)
End With
rowNum = Range("A" & Rows.Count).End(xlUp).row
Cells(rowNum, 18).Value = Mid(source, 23, 2) & " " & Mid(source, 21, 2) & " " & Mid(source, 19, 2)
Cells(rowNum, 19).Value = Mid(source, 11, 2) & "/" & Mid(source, 13, 2) & "/" & Mid(source, 15, 4)
ElseIf Mid(source, 1, 2) = "23" Then
With destination.Columns("V:W")
.AutoFilter field:=1, Criteria1:=Mid(source, 3, 4)
.AutoFilter field:=2, Criteria1:=Mid(source, 7, 4)
End With
rowNum = Range("A" & Rows.Count).End(xlUp).row
Cells(rowNum, 28).Value = Mid(source, 23, 2) & " " & Mid(source, 21, 2) & " " & Mid(source, 19, 2)
Cells(rowNum, 29).Value = Mid(source, 11, 2) & "/" & Mid(source, 13, 2) & "/" & Mid(source, 15, 4)
End If
Loop
Selection.AutoFilter
ご協力いただければ幸いです!
ああ私の良さ。どうもありがとうございます! – user6300479