![]() |
Adding rows from sheets to one sheet
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 |
Adding rows from sheets to one sheet
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! |
Adding rows from sheets to one sheet
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! |
Adding rows from sheets to one sheet
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! |
All times are GMT +1. The time now is 03:05 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com