anandvarma
Active Member
- Joined
- Apr 26, 2011
- Messages
- 384
- Office Version
- 365
- Platform
- Windows
- MacOS
i have " ^ " separated text file, i want to import this file to excel using the follow VBA code
Sub ImportData()
Dim counter As Long
Dim strMyLine As String
Dim myFile As Long
Dim strData() As String
myFile = FreeFile
Open "C:\Documents and Settings\anandavarma\Desktop\test.txt" For Input As #myFile
Do While Not EOF(myFile)
Line Input #myFile, strMyLine
strData = Split(strMyLine, "^")
For counter = LBound(strData) To UBound(strData)
ActiveCell.Offset(0, counter).Value = strData(counter)
Next
ActiveCell.Offset(1, 0).Select
Loop
Close #myFile
Columns.AutoFit
Range("A1").Select
End Sub
what is happening is all data is imported in first row only
please help me
Sub ImportData()
Dim counter As Long
Dim strMyLine As String
Dim myFile As Long
Dim strData() As String
myFile = FreeFile
Open "C:\Documents and Settings\anandavarma\Desktop\test.txt" For Input As #myFile
Do While Not EOF(myFile)
Line Input #myFile, strMyLine
strData = Split(strMyLine, "^")
For counter = LBound(strData) To UBound(strData)
ActiveCell.Offset(0, counter).Value = strData(counter)
Next
ActiveCell.Offset(1, 0).Select
Loop
Close #myFile
Columns.AutoFit
Range("A1").Select
End Sub
what is happening is all data is imported in first row only
please help me