+ Reply to Thread
Results 1 to 4 of 4

Need Macro to copy data from a single sheet from work books in the same directory.

  1. #1
    Registered User
    Join Date
    06-21-2012
    Location
    Washington DC
    MS-Off Ver
    Excel 2010
    Posts
    2

    Need Macro to copy data from a single sheet from work books in the same directory.

    Hello all,

    I am new to VBA. I need a macro to look at all .xls files in a directory and combine the data to a single master sheet. I also need it to unhidde all the columns before copying the data before copying it to the master sheet. I tried the code below but I am just getting errors. I am using excel 2010.

    [CODE] Sub Combine()


    Fpath = "C:\Users\Documents\Service Partners Alliance\Robin Sing\consolidation"
    Fname = Dir(FilePth & "*.xls")

    Do While Fname <> ""
    Workbooks.Open Fpath & Fname
    Sheets("Detail - 05-2012").Copy After:=Workbooks("Master.xlsm").Sheets(Workbooks("Master.xlsm").Sheets.Count)
    Workbooks(Fname).Close SaveChanges:=False
    Fname = Dir
    Loop

    End Sub [CODE]

    Thanks in advance.
    Last edited by bird970; 06-21-2012 at 06:12 PM.

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Need Macro to copy data from a single sheet from work books in the same directory.

    bird970,

    Welcome to the forum!
    As a side note, the code tags didn't work becuase you're missing the slash "/" in the ending code tag. It should be [/CODE]

    As to your query, as long as each workbook in that folder has a sheet named 'Detail - 05-2012' and that worksheet has headers in row 1, then this should work for you:
    Please Login or Register  to view this content.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    06-21-2012
    Location
    Washington DC
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Need Macro to copy data from a single sheet from work books in the same directory.

    Thanks so much the query worked perfectly.

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Need Macro to copy data from a single sheet from work books in the same directory.

    You're very welcome

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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