+ Reply to Thread
Results 1 to 24 of 24

Exel master workbook

  1. #1
    Registered User
    Join Date
    12-04-2012
    Location
    canada
    MS-Off Ver
    Excel 2007
    Posts
    12

    Exel master workbook

    Hey,

    I noticed that a lot you are good help with pulling data from mutiple excel files to a seperate workbook. I am having trouble with some of the macros I found.
    I need to pull data from a few different cells on a paticular sheet from a paticular workbook.

    For example the macro would look into filepath:
    C:\Scorecards

    And there are multiple xlsx. files/workbooks named:
    scorecard1
    scorecard2
    scorecard3
    scorecard4

    The the macro would need compile data from each file/workbook from a certain sheet from certain cells:
    scorecard1 - Sheet 2 copy data from cells: A1, AB16, AG16

    Then past the copied data from the selected cells into a new file/masterworkbook-
    Past data from and into:
    scorecard1-sheet2-cells A1, AB16, AG16 to Masterworkbook-cells A2, B2, C2
    scorecard2-sheet2-cells A1, AB16, AG16 to Masterworkbook-cells A3, B3, C3
    scorecard3-sheet2-cells A1, AB16, AG16 to Masterworkbook-cells A4, B4, C4
    scorecard4-sheet2-cells A1, AB16, AG16 to Masterworkbook-cells A5, B5, C5

    I really hope you can help me,

    Thanks

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Exel master workbook

    After running the macro the 1st time, if you make changes to the individual workbooks and want to run the macro again, do you want the contents of the master file to be cleared and fresh data input?

    Will the master file already have data in it or should the macro start with a new workbook each time you run the macro?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    12-04-2012
    Location
    canada
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Exel master workbook

    If possible, have the macro create a new workbook so i can save/keep the old one. I would like to run the macro once a month for new data collected.

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Exel master workbook

    Try this code - change the bold areas as required -
    Please Login or Register  to view this content.
    Copy the Excel VBA code
    Select the workbook in which you want to store the Excel VBA code
    Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    Choose Insert | Module
    Where the cursor is flashing, choose Edit | Paste

    To run the Excel VBA code:
    Choose View | Macros
    Select a macro in the list, and click the Run button

  5. #5
    Registered User
    Join Date
    12-04-2012
    Location
    canada
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Exel master workbook

    I get this error when i run it
    Untitled.jpg

    and this is the line it want to be debugged
    Set sourceData = sourceBook.Worksheets("Sheet2")

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Exel master workbook

    Hmm thats the first time i have seen that error. Is your sheet named Sheet2 in your file from which the data needs to be copied?

  7. #7
    Registered User
    Join Date
    12-04-2012
    Location
    canada
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Exel master workbook

    No, I have ir named DATA but it is sheet2, shoud i change it from Set sourceData = sourceBook.Worksheets("Sheet2")
    to Set sourceData = sourceBook.Worksheets("DATA")
    ?

  8. #8
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Exel master workbook

    Yes. Ensure it matches exactly with your sheet name with regards to spelling and case.

  9. #9
    Registered User
    Join Date
    12-04-2012
    Location
    canada
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Exel master workbook

    Hmm
    now im get this error
    Untitled2.png

    Then asks to debug this line
    lastrow = Master.Worksheets(1).Range("A" & Rows.Count).End(xlUp).Row.

    It does prompt a workbook with the headers, but no values are being copy and pasted below the headers

  10. #10
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Exel master workbook

    That code is fine as long as there is no dot (.) after row. Just check that and try the code again.

  11. #11
    Registered User
    Join Date
    12-04-2012
    Location
    canada
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Exel master workbook

    Still getting the same error.
    The data in cells that are choosen to be slected are populated from a formula, would that affect the code?
    ex AB16 =IF(Q16>=95,"5.0",IF(Q16>=90,"4.0",IF(Q16>=85,"3.0",IF(Q16>=80,"2.0","1.0")))) and that is 5.0 which the value i want pasted into the masterbook

  12. #12
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Exel master workbook

    No the formula should not affect the macro.

  13. #13
    Registered User
    Join Date
    12-04-2012
    Location
    canada
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Exel master workbook

    When I do run the macro with the code above, it will create a workbook with Header1, Header2, and Header3 but it doesnt paste any data in the next row from my other workbooks from my path. Although it does open one xlsx file but none of the others.

  14. #14
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Exel master workbook

    Can you attach a sample file?

    To Attach a File:

    1. Click on Go Advanced
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the Browse... button to locate your file for uploading.
    6. This will open a new window File Upload.
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the Upload button and wait until the file has uploaded.
    10. Close the window and then click Submit.

  15. #15
    Registered User
    Join Date
    12-04-2012
    Location
    canada
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Exel master workbook

    Here is an example of an xlsx file im pulling data from
    Attached Files Attached Files

  16. #16
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Exel master workbook

    So you have multiple files like this one which need to have their DATA tab consolidated into a new workbook right?

  17. #17
    Registered User
    Join Date
    12-04-2012
    Location
    canada
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Exel master workbook

    Yes, that is correct

  18. #18
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Exel master workbook

    I tested the code given in post 4 and except for changing
    Please Login or Register  to view this content.
    , i didnt make any other changes. It worked fine at my end.

  19. #19
    Registered User
    Join Date
    12-04-2012
    Location
    canada
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Exel master workbook

    Strange, I still get the same error from post 9. Could it have to do with the version of excel I am using(2007)? or something in my microsoft visual basic options?
    I really appreciate the help btw

  20. #20
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Exel master workbook

    Try moving that line - lastrow = ...etc above the "With Sourcedata" line. I ran it with this option and it worked as well.

    You have put the code in a standard module right, as per the instructions i gave you?

    All the files are present in "C:\Scorecards" right?

  21. #21
    Registered User
    Join Date
    12-04-2012
    Location
    canada
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Exel master workbook

    I believe i followed the instrucitons correctly, And I tried running it with the "lastrow" line above "with sourcedata"
    here is a screen shot of the line highlighted for me to debugdebug.jpg


    If i remove the "lastrow" line completly it will run the macro and collect the data from the cells i asked for, but only from one xlsx. file, not all xlsx files. and there is no headers obv
    Last edited by bblake; 12-05-2012 at 04:00 PM.

  22. #22
    Registered User
    Join Date
    07-27-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007/2010
    Posts
    86

    Re: Exel master workbook

    Not sure if this will help. I modified a bit.
    Please Login or Register  to view this content.
    Boon

  23. #23
    Registered User
    Join Date
    12-04-2012
    Location
    canada
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Exel master workbook

    Yes! that helped! Thank you Arlette and Boon! :D

  24. #24
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Exel master workbook

    Am glad it worked. Though there was nothing wrong with my code line. I wonder why it was not working.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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