![]() |
import data
Hi!
I am making a macro that imports data and makes a list of the one I need. I only need data in the first 5 lines. since it is a rather long file I would like to only import the first lines. In the import dialog there is an option that allows for a starting line. How do I stop importing after 5 lines. Jacob |
import data
You can either import the entire file and clear the unneeded data or use
VB's file i/o commands in a macro like this: Sub FileImport() Dim ResultStr As String Dim FileName As String Dim FileNum As Integer Dim Counter As Double FileName = InputBox("Name of text file to import:") If FileName < "" Then FileNum = FreeFile() Open FileName For Input As #FileNum While Not EOF(FileNum) And Counter < 5 Counter = Counter + 1 Line Input #FileNum, ResultStr Cells(Counter, 1).Value = ResultStr Wend Close End If End Sub -- Jim Rech Excel MVP "Jacob" wrote in message ... | Hi! | | I am making a macro that imports data and makes a list of the one I need. | | I only need data in the first 5 lines. since it is a rather long file I | would like to only import the first lines. In the import dialog there is an | option that allows for a starting line. | | How do I stop importing after 5 lines. | | Jacob |
All times are GMT +1. The time now is 11:37 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com