how to find end of line in VBA

anandvarma

Active Member
Joined
Apr 26, 2011
Messages
384
Office Version
  1. 365
Platform
  1. Windows
  2. 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
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Could this be a simpler way of accomplishing the same goal? It uses Workbook open (even though it's a text file) and specifies the delimiter as a "^".
Code:
    Workbooks.OpenText Filename:= _
        "C:\Documents and Settings\anandavarma\Desktop\test.txt", Origin:=437, StartRow _
        :=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
        ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=False _
        , Space:=False, Other:=True, OtherChar:="^", TrailingMinusNumbers:=True
Hope that helps,
Cindy
 
Upvote 0

Forum statistics

Threads
1,224,550
Messages
6,179,463
Members
452,915
Latest member
hannnahheileen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top