Auto-reading a txt file

pichapple

New Member
Joined
Feb 27, 2011
Messages
2
Hello,

How can I get Excel to copy a TXT file, line by line but start a new sheet when it reads a line starting with specific characters...

For example... here's the sequence I need it to follow

import a txt file, (ask user for file)
import line by line until it reaches a line begining with "Vessel: " (there is other text after this initial text marker)
when reached, begin a new sheet and follow same process from remaining file...

Basically, I have a HUGE text file which needs to be broken down into separate files/sheet, and need a way of doing this without doing it manually...

Thanks everyone!
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Easy. Show us a sample of your data.

How would you like the worksheets named?
 
Upvote 0
Code:
Sub snb()
  open "E:\import.txt" for input as #1
    sq=split(input(LOF(1),#1),vbcrlf & "Vessel")
  close #1
 
  for j=0 to ubound(sq)
    with thisworkbook.sheets.add
      sn=split(sq(j).vbcrLF)
      .cells(1).resize(ubound(sn)+1)=application.transpose(sn)
    end with
  next
End Sub
 
Upvote 0
Thanks!

ok, so Im not quite an excel wizz, so excuse my questions. I pasted this into a macro, but it got stuck on the line

sn = Split(sq(j).vbCrLf)

If it's easier, I can post a data sample?

Thanks for your help everyone!
 
Upvote 0
That period should be a comma in that line:

sn = Split(sq(j),vbCrLf)

Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,224,506
Messages
6,179,159
Members
452,892
Latest member
yadavagiri

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