Accepted answer
-
Viorel 117.9K Reputation points
2021-03-25T09:12:43.29+00:00 It seems that you should remove ‘Pos2 = Len(TextLine)’ or use another variable for length instead of Pos2.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
Please help to error
due to last line below
If Trim(TextLine) <> "" Then Pos0 = InStr(TextLine, ",") Pos1 = InStr(Pos0 + 1, TextLine, ",") Pos2 = InStr(Pos1 + 1, TextLine, ",") Pos3 = InStr(Pos2 + 1, TextLine, ",") Pos4 = InStr(Pos3 + 1, TextLine, ",") Pos5 = InStr(Pos4 + 1, TextLine, ",") Pos6 = InStr(Pos5 + 1, TextLine, ",") Pos7 = InStr(Pos6 + 1, TextLine, ",") Pos8 = InStr(Pos7 + 1, TextLine, ",") Pos9 = InStr(Pos8 + 1, TextLine, ",") Pos10 = InStr(Pos9 + 1, TextLine, ",") Pos2 = Len(TextLine) If Not Pos0 > 0 And Not Pos1 > 0 Then Para_Message = "Invalid line -'" & TextLine & "' has been got from list file." MsgBox Para_Message Close #iFile Exit Sub Else RowID = RowID + 1 Worksheets("Main").Unprotect Password:="hkg1317" Worksheets("Main").Cells(RowID, 1).Value = Mid(TextLine, 1, Pos0 - 1) Worksheets("Main").Cells(RowID, 2).Value = Mid(TextLine, Pos0 + 1, Pos1 - Pos0 - 1) Worksheets("Main").Cells(RowID, 3).Value = Mid(TextLine, Pos1 + 1, Pos2 - Pos1 - 1) Worksheets("Main").Cells(RowID, 4).Value = Mid(TextLine, Pos2 + 1, Pos3 - Pos2 - 1)
TextLine is line below
"NZ2,ABC,6,N,TWKLG,8501,8529,1,,"
It seems that you should remove ‘Pos2 = Len(TextLine)’ or use another variable for length instead of Pos2.