Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Okay, I am a newbie at Excel code, so please be patient with me. I am
looking at a way of taking all xls files in one folder, copying the second row from each sheet and pasting it into a template that's already opened. I won't know the name of the files in the folder, just that they will end in xls and that only the second row will need to be copied (I think it will go up to the 230th column) into the template, starting in the second row and continuing on down the sheet until all are copied into this one file. I am pretty sure this will involve a looping process, but I am not sure how to programmatically accomplish this. TIA, Jason |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try this, I didn't test it so there might be some trouble shooting
involved. Also, I have "C:\My docs" hard coded as the location of your xls files, and Book1 as the name of your template. Sub Macro2() Dim Filename As String, Book1row As Integer Filename = Dir("C:\My docs\" & "*.xls") Book1row = 1 Do While myname < "" Workbooks.Open Filename:="C:\My docs\" & Filename Rows("2:2").Copy Windows("Book1").Activate Range("A" & Book1row).Select ActiveSheet.Paste Windows(Filename).Close Book1row = Book1row + 1 myname = Dir Loop End Sub *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Claud,
Thanks very much. Well, when I ran the code I didn't get any errors, but nothing happened either. Here is what I have: ublic Sub CombineFiles() Dim Filename As String, Book1row As Integer Filename = Dir("C:\BRPT Files\" & "*.xls") Book1row = 1 Do While myname < "" Workbooks.Open Filename:="C:\BRPT Files\" & Filename Rows("2:2").Copy Windows("Comment1").Activate Range("A" & Book1row).Select ActiveSheet.Paste Windows(Filename).Close Book1row = Book1row + 1 myname = Dir Loop End Sub Just a few notes: The excel sheet (Comment1.xls) I want everything pasted into will be open during this process. The files that need to be open and copied from are located in the C:\BRPT Files\ directory. Thanks again for your help. -Jason "Claud Balls" wrote: Try this, I didn't test it so there might be some trouble shooting involved. Also, I have "C:\My docs" hard coded as the location of your xls files, and Book1 as the name of your template. Sub Macro2() Dim Filename As String, Book1row As Integer Filename = Dir("C:\My docs\" & "*.xls") Book1row = 1 Do While myname < "" Workbooks.Open Filename:="C:\My docs\" & Filename Rows("2:2").Copy Windows("Book1").Activate Range("A" & Book1row).Select ActiveSheet.Paste Windows(Filename).Close Book1row = Book1row + 1 myname = Dir Loop End Sub *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Made a mistake, put the Filename variable where the myname variable is
at. *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Linked sheets, blank cells and adding new rows | Excel Worksheet Functions | |||
adding sheets based upon a template sheet | Excel Worksheet Functions | |||
Adding rows to tables in 2 different sheets | Excel Discussion (Misc queries) | |||
SIMULTANEOUSLY adding rows in two sheets | Excel Programming | |||
How to control sheet number when adding and deleting sheets? | Excel Programming |