VBA Line Input vs Input

I want to read a file written by c, where each line is split by / n. I want to read this file and compare it with excel data. I used input #1, data . But I want to read the line with "," (comma), so I used Line Input #1, data .

when I check that the "data" contains excel data, although they are the same as false.

 Activecell="KVK" Line Input #1,data msgbox ActiveCell=data 

prints false even if the KVK data.

Thank you and welcome help in advance, Vamshi krishna

 Dim fpath, fnum, s fpath = Application.GetOpenFilename fnum = FreeFile Open fpath For Input As fnum Range("A1").Activate Do While Not EOF(fnum) Line Input #fnum, s 'Input #fnum, s MsgBox s & " = " & ActiveCell & " " MsgBox s = ActiveCell ActiveCell.Offset(1, 0).Select Loop 

.txt has

 12 13 14 

data in the first column

 12 13 14 
+6
source share
2 answers

Try entering the code:

 Sub InputImage() Dim FileNum As Integer, i As Integer Dim fpath As String, s As String, cellVal As String fpath = Application.GetOpenFilename FileNum = FreeFile() Open fpath For Input As #FileNum i = 1 While Not EOF(FileNum) Line Input #FileNum, s ' read in data 1 line at a time cellVal = CStr(Cells(i, 1).Value) MsgBox s & " = " & cellVal & " " MsgBox s = cellVal ActiveCell.Offset(1, 0).Select i = i + 1 Wend End Sub 

If you check the viewport, cell data type (i, 1) .Value shows Variant / Double. Therefore, you need to convert to a string.

enter image description here

+4
source

Or use TextStream in the Scripting library, it is much better.

And please close the file when you are done with it, you must be the person who does not put the milk back in the refrigerator when you are done with it and just mess it up for everyone.

0
source

All Articles