question

Jackson1990-7147 avatar image
0 Votes"
Jackson1990-7147 asked Viorel-1 answered

Error to read

Hi,
Please help to error
81003-a20.png
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,,"


office-vba-dev
a20.png (5.1 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@Jackson1990-7147
Based on your description, your issue is more related to VBA code, as tag "office-excel-itpro" focuses on general issues about Excel clients, I will remove it. Thanks for your understanding.

0 Votes 0 ·

1 Answer

Viorel-1 avatar image
0 Votes"
Viorel-1 answered

It seems that you should remove ‘Pos2 = Len(TextLine)’ or use another variable for length instead of Pos2.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.