#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default 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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
import XML data...Is there a size limit on the import? MatthewG Excel Discussion (Misc queries) 0 February 10th 09 05:57 PM
How to Start Excel in Text Import Wizard for data import rlelvis Setting up and Configuration of Excel 0 July 10th 08 08:40 PM
Import external data, data includes Excel function allen davidson Excel Worksheet Functions 0 July 4th 08 12:39 PM
Tool bar: Data/Import external data/New database query Daniel Setting up and Configuration of Excel 3 February 28th 08 08:40 AM
Prevent equation from skipping data when referencing import data? lybrt98 Excel Discussion (Misc queries) 0 August 30th 05 05:01 PM


All times are GMT +1. The time now is 06:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"