Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Looping thru files extracting data

I need to extract a range of cells from 16 excel files and paste the
"values" into 1 file.
My extraction range is J26..L80 on a tab called "Linked Data".
My data files are labeled "anything Load 1.xls" where the name stays
the same but I increment the value 1 thru 16.

So I was hoping to have some way of opening the file open window,
picking the first file in the series and the macro would then loop thru
all 16 files and paste the data in to a separate temporary file.

My temp file would have these 3 columns of data then an empty column
then the next file would be opened and the "values" inserted next to it
similar to the following:

x x x x x x x x x x x x
x x x x x x x x x x x x
x x x x x x x x x x x x
x x x x x x x x x x x x

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Looping thru files extracting data

gtslabs shared this with us in microsoft.public.excel.programming:

I need to extract a range of cells from 16 excel files and paste the
"values" into 1 file.
My extraction range is J26..L80 on a tab called "Linked Data".
My data files are labeled "anything Load 1.xls" where the name stays
the same but I increment the value 1 thru 16.

So I was hoping to have some way of opening the file open window,
picking the first file in the series and the macro would then loop
thru all 16 files and paste the data in to a separate temporary file.

My temp file would have these 3 columns of data then an empty column
then the next file would be opened and the "values" inserted next to
it similar to the following:

x x x x x x x x x x x x
x x x x x x x x x x x x
x x x x x x x x x x x x
x x x x x x x x x x x x


Extracting data from Excel files can even be done without opening them!
http://www.rondebruin.nl/ado.htm#files

--
Amedee Van Gasse using XanaNews 1.17.4.1
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Looping thru files extracting data

This is very close to what you want. Code was pieced together from this
newsgroup. What's different is a) you multi-select all your files at once
and the code will loop through the Array of filenames. b) It will append
each file to the end of the previous file, down a single sheet. You will
need to modify it to count columns instead of rows to put the data across
the sheet. This is a good start with the basics of what you want.

Sub DAC_Report()
Dim basebook As Workbook
Dim mybook As Workbook
Dim sourceRange As Range
Dim destrange As Range
Dim SourceRcount As Long
Dim N As Long
Dim rnum As Long
Dim MyPath As String
Dim SaveDriveDir As String
Dim FName As Variant

SaveDriveDir = CurDir
'MyPath = "C:\Data"
'ChDrive MyPath
'ChDir MyPath
FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls),
*.xls", _
MultiSelect:=True)
If IsArray(FName) Then
Application.ScreenUpdating = False
Set basebook = ThisWorkbook
rnum = 1
basebook.Worksheets(1).Cells.Clear
'clear all cells on the first sheet

For N = LBound(FName) To UBound(FName)
Set mybook = Workbooks.Open(FName(N))
Set sourceRange = mybook.Worksheets(1).Range("A3:F53")
SourceRcount = sourceRange.Rows.Count
Set destrange = basebook.Worksheets(1).Cells(rnum, "A")

basebook.Worksheets(1).Cells(rnum, "G").Value = mybook.Name
' This will add the workbook name in column D if you want

sourceRange.Copy destrange
' Instead of this line you can use the code below to copy only
the values

' With sourceRange
' Set destrange = basebook.Worksheets(1).Cells(rnum,
"A"). _
' Resize(.Rows.Count, .Columns.Count)
' End With
' destrange.Value = sourceRange.Value

mybook.Close False
rnum = rnum + SourceRcount
Next
End If
Columns("G:G").Font.Size = 8
Columns("G:G").Font.Bold = True
' ChDrive SaveDriveDir
' ChDir SaveDriveDir
Application.ScreenUpdating = True
End Sub

Good Luck,
Mike F

"gtslabs" wrote in message
oups.com...
I need to extract a range of cells from 16 excel files and paste the
"values" into 1 file.
My extraction range is J26..L80 on a tab called "Linked Data".
My data files are labeled "anything Load 1.xls" where the name stays
the same but I increment the value 1 thru 16.

So I was hoping to have some way of opening the file open window,
picking the first file in the series and the macro would then loop thru
all 16 files and paste the data in to a separate temporary file.

My temp file would have these 3 columns of data then an empty column
then the next file would be opened and the "values" inserted next to it
similar to the following:

x x x x x x x x x x x x
x x x x x x x x x x x x
x x x x x x x x x x x x
x x x x x x x x x x x x



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Looping thru files extracting data

More examples here
http://www.rondebruin.nl/tips.htm


--
Regards Ron de Bruin
http://www.rondebruin.nl



"Amedee Van Gasse" wrote in message ...
gtslabs shared this with us in microsoft.public.excel.programming:

I need to extract a range of cells from 16 excel files and paste the
"values" into 1 file.
My extraction range is J26..L80 on a tab called "Linked Data".
My data files are labeled "anything Load 1.xls" where the name stays
the same but I increment the value 1 thru 16.

So I was hoping to have some way of opening the file open window,
picking the first file in the series and the macro would then loop
thru all 16 files and paste the data in to a separate temporary file.

My temp file would have these 3 columns of data then an empty column
then the next file would be opened and the "values" inserted next to
it similar to the following:

x x x x x x x x x x x x
x x x x x x x x x x x x
x x x x x x x x x x x x
x x x x x x x x x x x x


Extracting data from Excel files can even be done without opening them!
http://www.rondebruin.nl/ado.htm#files

--
Amedee Van Gasse using XanaNews 1.17.4.1



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
Extracting Data for .Txt Files By Unique Field Data La Excel Discussion (Misc queries) 3 July 17th 06 01:30 PM
Extracting data from multiple excel files. helphelp Excel Discussion (Misc queries) 2 May 10th 06 09:45 PM
help with looping range and extracting value Pb21 Excel Programming 3 October 19th 04 03:58 AM
Extracting Data from CSV files hce[_11_] Excel Programming 0 September 26th 04 08:46 AM
Extracting Data from CSV files hce[_9_] Excel Programming 1 September 25th 04 06:03 PM


All times are GMT +1. The time now is 01:55 AM.

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

About Us

"It's about Microsoft Excel"