VBA Line Input vs Input

excel, file-io, input, vba

Solution

Try below 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 in watch window the data type of cell(i,1).Value is showing Variant/Double. So there is need to convert into string.

Problem

I want to read a file written by c where each line is seperated by /n. I want read that file and compare it with data on excel. I used `input #1, data` . But I want to read a line with ","(comma), So i used `Line Input #1, data`. when i check that "data" with data on excel, though they are same, its saying false. ``` Activecell="KVK" Line Input #1,data msgbox ActiveCell=data ``` is printing false even if data is KVK. Thanks and Regards for Helping 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 first column ``` 12 13 14 ```

Original source