View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Extract data question

If the files were file1.txt to file1000.txt found in the C:\ directory:

Sub ABC()
Dim sh As Worksheet
Dim bk As Workbook
Dim i As Long
Set sh = ActiveSheet
For i = 1 To 1000
Set bk = Workbooks.Open("c:\file" & i & ".txt")
sh.Cells(i, 1) = bk.Worksheets(1).Cells(2, 1)
sh.Cells(i, 2) = bk.Worksheets(1).Cells(8, 1)
bk.Close Savechanges:=False
Next
End Sub

--
Regards,
Tom Ogilvy


"Nick" wrote in message
...
Hello,

I am completely new to VBA so I hope you will bear with me...
My problem is that I need to extract certain data is always in the same
format, ie

[STATION NUMBER]
12005
[END]
[CDS Details]
NAME,MUICK
LOCATION,INVERMUICK
NOMINAL AREA, 110.00
NOMINAL NGR,336400,794700
[End]

where I need to extract the 2nd and 8th lines, and place them in adjacent
colums in an excel file, then go to the next file down (named numerically)

Many many thanks for any help - I have about 1000 files to go through!

Nick