While running this code, I am getting
VBA 1004 error: "Application defined or Object defined error"
on the line indicated below. Why?
I am using Excel 2013. My spreadsheet has 2 sheets, Sheet1 and Sheet2.
Public Sub ImportTextFile()
Dim RowNdx As Long
Dim TempVal As String
Dim WholeLine As String
Application.ScreenUpdating = False
'On Error GoTo EndMacro:
RowNdx = 11
FName = Worksheets("Sheet1").Cells(1, 2).Value
Open FName For Input Access Read As #1
While Not EOF(1)
Line Input #1, WholeLine
Worksheets("Sheet1").Cells(RowNdx, 1).Value = WholeLine ' <~~~~~~ ERROR
RowNdx = RowNdx + 1
Wend
Application.ScreenUpdating = True
Close #1
End Sub
RowNdx
andWholeLine
when the error happens? – Jean-François CorbettWholeLine
that Excel doesn't like. Something like a Chr(13) without Chr(10) although that's not it. Can you loop through each letter of WholeLine on the line that causes the error andDebug.Print Mid$(WholeLine,i,1), Asc(Mid$(WholeLine,i,1))
wherei
is your control variable? It might be useful to see what kind of characters are in there. – Dick Kusleika