Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default Copying data from many files

Hello,

Using Excel XP.

I have a number of files in one directory (say C:\Temp).
Each file has two sheets - "Infor" and "Sales". The
layout and format of "Sales" is the same in all files.
Example for 2 files follows.

Cell C1 of the "Info" sheet in each workbook contains the
customers name (= the name of each workbook respectively)

(b) = blank cell

ABC.xls - Sales worksheet (A1: C downwards)
ItemCode ItemDesc Type1$ Type2$
101 Item114 $101 (b)
102 Item102 $50 (b)
203 Item203 (b) $75
204 Item204 (b) $35


XYZ.xls - Sales worksheet (A1: C downwards)

ItemCode ItemDesc Type1$ Type2$
114 Item114 $23 (b)
102 Item102 $50 (b)
103 Item103 $56 (b)
203 Item203 (b) $75
204 Item204 (b) $35
205 Item205 (b) $45

From each file, I need to copy the data from each "Sales"
worksheet to Sheet1 in "Summary_Sales.xls", in the
following format:

CustName ItemCode ItemDesc Type1$ Type2$
ABC 101 Item114 $101 (b)
ABC 102 Item102 $50 (b)
ABC 203 Item203 (b) $75
ABC 204 Item204 (b) $35
XYZ 114 Item114 $23 (b)
XYZ 102 Item102 $50 (b)
XYZ 103 Item103 $56 (b)
XYZ 203 Item203 (b) $75
XYZ 204 Item204 (b) $35
XYZ 205 Item205 (b) $45

I am familiar with FileSearch to open/close each file in
a directory, but I'm failing on the looping syntax to
populate "Summary_Sales.xls". I have unsuccessfully tried
to adapt the syntax from a macro authored Mr. T. Ogilvy
found at http://makeashorterlink.com/?A14813CA8.

I will appreciate any assistance on this matter.

TIA

Richard


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Copying data from many files

If I understand the problem correctly, you should be able to do it as a
nested loop, copying each cell, one at a time, from the Sales sheet of the
file in question, to the Summary spreadsheet. I would write it as a separate
subroutine to which you pass the name of the file. See if this makes sense:

Sub Summarize()
SummarizeFile "C:\Files\ABC.XLS"
SummarizeFile "C:\Files\XYZ.XLS"
End Sub

Sub SummarizeFile(ByVal sFileName As String)

Dim lrowcount As Long
Dim lrow As Long
Dim lrow_summary As Long
Dim icolcount As Integer
Dim icol As Integer

' first empty row in summary sheet:
lrow_summary = ThisWorkbook.Worksheets(1).UsedRange.Rows.Count + 1

Workbooks.Open sFileName
Worksheets("Sales").Activate

' determine how many rows and columns are used:
lrowcount = ActiveSheet.UsedRange.Rows.Count
icolcount = ActiveSheet.UsedRange.Columns.Count

For lrow = 2 To lrowcount
ThisWorkbook.Worksheets(1).Cells(lrow_summary, 1).Value = sFileName
For icol = 1 To icolcount
ThisWorkbook.Worksheets(1).Cells(lrow_summary, icol + 1).Value =
_
ActiveSheet.Cells(lrow, icol).Value
Next icol
lrow_summary = lrow_summary + 1
Next lrow
ActiveWorkbook.Close

End Sub



"David" wrote in message
...
Hello,

Using Excel XP.

I have a number of files in one directory (say C:\Temp).
Each file has two sheets - "Infor" and "Sales". The
layout and format of "Sales" is the same in all files.
Example for 2 files follows.

Cell C1 of the "Info" sheet in each workbook contains the
customers name (= the name of each workbook respectively)

(b) = blank cell

ABC.xls - Sales worksheet (A1: C downwards)
ItemCode ItemDesc Type1$ Type2$
101 Item114 $101 (b)
102 Item102 $50 (b)
203 Item203 (b) $75
204 Item204 (b) $35


XYZ.xls - Sales worksheet (A1: C downwards)

ItemCode ItemDesc Type1$ Type2$
114 Item114 $23 (b)
102 Item102 $50 (b)
103 Item103 $56 (b)
203 Item203 (b) $75
204 Item204 (b) $35
205 Item205 (b) $45

From each file, I need to copy the data from each "Sales"
worksheet to Sheet1 in "Summary_Sales.xls", in the
following format:

CustName ItemCode ItemDesc Type1$ Type2$
ABC 101 Item114 $101 (b)
ABC 102 Item102 $50 (b)
ABC 203 Item203 (b) $75
ABC 204 Item204 (b) $35
XYZ 114 Item114 $23 (b)
XYZ 102 Item102 $50 (b)
XYZ 103 Item103 $56 (b)
XYZ 203 Item203 (b) $75
XYZ 204 Item204 (b) $35
XYZ 205 Item205 (b) $45

I am familiar with FileSearch to open/close each file in
a directory, but I'm failing on the looping syntax to
populate "Summary_Sales.xls". I have unsuccessfully tried
to adapt the syntax from a macro authored Mr. T. Ogilvy
found at http://makeashorterlink.com/?A14813CA8.

I will appreciate any assistance on this matter.

TIA

Richard




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
Copying from different files into 1 LiAD Excel Discussion (Misc queries) 1 November 4th 09 01:57 PM
Need Help Copying Excel Files to a CD jm47 Excel Discussion (Misc queries) 6 November 26th 08 05:44 AM
Copying Files RH206 Excel Discussion (Misc queries) 2 April 1st 08 08:21 PM
Copying files fds Excel Worksheet Functions 1 July 27th 05 12:55 AM
Copying data across 2 xcel files Gandei Excel Programming 1 December 5th 03 04:58 PM


All times are GMT +1. The time now is 08:19 PM.

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"