+ Reply to Thread
Results 1 to 8 of 8

Macro for Copying Cels from All Workbooks to a Single Master Workbook

  1. #1
    Registered User
    Join Date
    05-22-2013
    Location
    Atlanta
    MS-Off Ver
    Excel 2007
    Posts
    4

    Macro for Copying Cels from All Workbooks to a Single Master Workbook

    Hi!
    I’m new to the forum and I’m trying to get a crash course to VBA. The simple version of my issue is I have a folder on my C drive “C/TEMP/” in which I want to copyl the data from any and all closed xlsx workbooks placed within that folder from four different cells: C1, F1, F34, and G34 from sheet1, and place in a Master.xlsm sheet2 in cells in separate columns.

    What I am doing is trying to take the data from these four cells as time sheets and create one master payroll sheet to turn in twice a month. The columns would correspond to each of the four cells.

    I’ve plowed through a good many posts everywhere and my problem is I simply don’t have enough experience with the coding language to determine where things are going wrong although I’ve come close (I think) to what I’m needing to do. A lot of what I’ve come across is oh so close, but not quite there if you know what I mean. Not for lack of trying first at least.

    Any help would be greatly appreciated.

    Thanks!

    Johnny
    Last edited by JohnnyJ2013; 05-24-2013 at 11:08 PM.

  2. #2
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Macro for Copying Cels from All Workbooks to a Single Master Workbook

    Unfortunately your data is non-contiguous, which makes it a good bit more difficult. Nonetheless, I wanted to be sure you had reviewed this - specifically the section on 'Workbooks'.
    Perhaps it was the Noid who should have avoided me...
    If you are satisfied with my solution click the small star icon on the left. Thanks
    1. Make a copy of your workbook and run the following code on your copy (just in case)
    2. With excel open, press ALT+F11 to open the Visual Basic Editor (VBE). From the "Insert" menu, select "Module".
    3. Paste the code from above into the empty white space. Close the VBE.
    4. From the developer tab, choose "Macros", select the Sub Name, and click "Run".

  3. #3
    Registered User
    Join Date
    05-22-2013
    Location
    Atlanta
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Macro for Copying Cels from All Workbooks to a Single Master Workbook

    Good info for sure, I'll read through it and pick up what i can. Hopefully it will help. Funny how it seems simple on the outset.

    Thank you

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro for Copying Cels from All Workbooks to a Single Master Workbook

    You wanted to copy C1, F1, F34, and G34 from sheet1 in to where? Where are the copied cells pasted in to? It would have been easier if you could attach a sample book? To attach a sample, go to advance then attachment.

  5. #5
    Registered User
    Join Date
    05-22-2013
    Location
    Atlanta
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Macro for Copying Cels from All Workbooks to a Single Master Workbook

    I am needing to copy cells F1, C1, F34 and F35 from the "Time Sheet" tab on all the workbooks in the C:\Temp folder and pasted into Sheet1 on the Mater.xlsm as a list of content from those cells. I've attached the files as you suggested and have added a few highlights so perhaps a better explnation.

    Thank you very much for your help.


    Master.xlsmTest1.xlsxTest2.xlsx

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro for Copying Cels from All Workbooks to a Single Master Workbook

    Johnny,
    Merge cells and VBA are not good friends. You have merged cells in time sheets. VBA will not copy merged cells, so I have to unmerge them.
    I have tested it, as you can see, I used my own path: FolderPath = "C:\Marcotest"
    You need to change this path to your folder ,i.e. C drive “C/TEMP/”. I do not want to put this in to the code as there may be typo, or space, so I left it for you to fill it in.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    05-22-2013
    Location
    Atlanta
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Macro for Copying Cels from All Workbooks to a Single Master Workbook

    AB thanks a bunch, works perfect. Just what I was looking for and a great start to build upwards from. Did you code that from scratch or are you able to use the recorder? I gave the recorder a try but there was still too much code missing (and far too much excess) for all the details to work together.

    Thanks so much!

    Johnny

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro for Copying Cels from All Workbooks to a Single Master Workbook

    Johnny,
    I am not sure if it is possible to code it using recorded macro. Even if it is possible, it will take lots of pages in coding and may take a while to run it. Recoded macros are great for learning purposes, but not efficient.
    The code is not that complicated as it appears to be. It is a normal merging data code with opening folders added a bit complication. Most codes you find on -line search on merging from folders are very similar.

+ 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