+ Reply to Thread
Results 1 to 3 of 3

Copying multiple files to 1 new workbook

Hybrid View

  1. #1
    Registered User
    Join Date
    09-10-2008
    Location
    Derby
    Posts
    1

    Copying multiple files to 1 new workbook

    Hi
    I'm new to VBA macro scripting in Excel. However, I have the below code, which I need help with.

    The idea is it opens a number of files from my Y:/Scripts4/ folder names 1.xls, 2.xls, 3.xls, 4.xls etc and, for each one it opens, it copies cell range B10:O29 to a new file, I've just called "collate_new.xls"

    Everything works, except the line in bold, so I assume I have this wrong. Can anyone help?

    Thanks
    Tim

    p.s also, I want the data to be pasted into collate_new, and then the next set of data to be pasted after it etc, not overwritten. Not sure if the code below allows me to do that, but that's the aim.

    Sub collate_new()
    
    Dim sFile As String
    Dim arFiles(100) As String
    Dim i As Integer, j As Integer
    
    sFile = Dir$("Y:\Scripts4\*.xls", vbNormal)
        i = 0
        
    ' Fills array
        Do While sFile <> ""
          arFiles(i) = sFile
          sFile = Dir$()
           i = i + 1
        Loop
    ' Loop opens, copys and pastes
        For j = 0 To i - 1
            Workbooks.Open Filename:=arFiles(j)
            Closerfile = arFiles(j)
        Range("B10:O29").Copy
             Windows("Collate_new").Activate
        ActiveSheet.Paste
             Windows(arFiles(j)).Activate
            ActiveSheet.Close
      
             
        Next
    
    End Sub
    Last edited by royUK; 09-10-2008 at 08:07 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Please take the time to read the Forum Rules & use Code Tags in future.

    If you check the earlier posts, I posted code to do this only yesterday.

    here's a link

    http://www.excelforum.com/excel-prog...n-of-data.html
    Last edited by royUK; 09-10-2008 at 08:20 AM. Reason: add link
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,526
    Something like this could work
    ActiveSheet.Range("B10:O29").Copy Destination:=Workbooks("Collate_new").Sheets("Sheet1").Range("AA65536").End(xlUp).Offset(1, 0)
    This will paste to the first blank cell in column A(May have to change the sheet name)
    Look at this post for an example
    http://www.excelforum.com/excel-prog...-into-one.html

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Need Truth on Shared workbook & VB
    By dimitrz in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 08-29-2008, 01:42 AM
  2. Change a page number on a workbook with multiple sheets
    By sengelbrecht in forum Excel General
    Replies: 3
    Last Post: 08-21-2007, 04:01 PM
  3. Convert Multiple CSV Files to XLS Files Automatically
    By davehunter in forum Excel General
    Replies: 0
    Last Post: 07-11-2007, 05:42 AM
  4. Pivot table across multiple tabs in a workbook
    By mbrant in forum Excel General
    Replies: 4
    Last Post: 03-09-2007, 01:19 PM
  5. Copying Data from workbook a to workbook b, many times
    By jhumphrey in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-01-2007, 12:41 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1