copy data from txt file to excel sheet

vinod9111

Active Member
Joined
Jan 21, 2009
Messages
426
Hi All,

I have one huge text file which i need to copy into excel sheets. The data is huge and may run upto 6 to 7 sheets. I need a macro to copy the data from the text file and paste into the excel sheet till 60000 row and then the remaining data need to be pasted in other sheets till 60000 row of each sheet.

Any help will be appreciated.

regards,

Vinod
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
See if you can adapt this - it imports 4 columns of data.

Code:
Sub ImportPostCodes()
Dim iFreeFile As Integer, i As Long, path As String, InputLine
Dim ws As Worksheet, LineArray, t As Date
t = Now
Set ws = ActiveSheet
Reset
iFreeFile = FreeFile
path = ThisWorkbook.path
Open path & "\" & "PostCodeData.txt" For Input As #iFreeFile
Application.ScreenUpdating = False
i = 1
Do While Not EOF(iFreeFile)
    Line Input #iFreeFile, InputLine
    LineArray = Split(InputLine, vbTab)
    ws.Range(Cells(i, 1), Cells(i, 4)).Value = LineArray
    i = i + 1
    If i > 65536 Then
        ThisWorkbook.Save
        Sheets.Add after:=ws
        Set ws = ActiveSheet
        i = 1
    End If
Loop
ThisWorkbook.Save
Close #iFreeFile
Application.ScreenUpdating = True
MsgBox "Time elapsed" & vbTab & Format(Now - t, "hh:mm:ss")
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,504
Messages
6,179,144
Members
452,891
Latest member
JUSTOUTOFMYREACH

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