ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   import from text file (https://www.excelbanter.com/excel-discussion-misc-queries/126443-import-text-file.html)

jason2444

import from text file
 
have a text file that is more lines than can fit in a single worksheet in
excel how do I import the data from that text sheet on to multiple sheets
without importing the same lines more than once.

ufo_pilot

import from text file
 
You could open the txt file in notepad, cut half of it, paste and save it as
1.txt the other half as 2.txt
then open each in a separate excel sheet
Not that this is the best way if you need to do this more often, but it
should work.


"jason2444" wrote:

have a text file that is more lines than can fit in a single worksheet in
excel how do I import the data from that text sheet on to multiple sheets
without importing the same lines more than once.


Dave O

import from text file
 
Another alternative is to run this code: it opens the original file and
creates sequentially numbered sub-files, which you can import to Excel.
Note you'll need to adjust the file path and possibly the TXT file
extension. The sub-files are called "Target" in this code, which you
can change- but you'll need to change all instances within the code.
You can adjust the number of rows per file from 60,000 to whatever is
appropriate. Enjoy!

Sub Import_Trim()
Dim Lyne As String
Dim FileCount As Byte, K As Byte
FileCount = 1

Open "c:\directory path\Source File Name.txt" For Input As #1
Open "c:\directory path\Target1.txt" For Output As #2

On Error Resume Next
Do While Not EOF(1)
For K = 1 To 60000
Line Input #1, Lyne
Print #2, Lyne
Next K

Close #2
FileCount = FileCount + 1
Open "c:\directory path\Target" & FileCount & ".txt" For Output As #2
Loop

Close #1
Close #2
MsgBox "Done."
End Sub



All times are GMT +1. The time now is 07:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com