Closed Thread
Results 1 to 16 of 16

Master and slave workbooks

  1. #1
    Registered User
    Join Date
    01-28-2009
    Location
    New York, USA
    MS-Off Ver
    Excel 2007
    Posts
    46

    Master and slave workbooks

    I have a Master workbook that contains the complete sales for the entire business. This is based on input from 12 different departments. These 12departments have their own slave Excel workbook that they enter information into. The 13 files are all located in the same directory on a network folder.

    What I want to do is to automatically gather all the entries from the 12 slave workbooks to the master workbook whenever the macro I am trying to create is run. There is no way of knowing how many new entries each workbook will contain and they have to be added so that that they don't overwrite eachother and so that they are put in sequence after the last row in the master workbook.

    Now the information to be gathered is located on the first worksheet in all the three workbooks. The destination sheet in the Master workbook is also the first worksheet in the workbook. The structure of the information that I want to copy is equal on all the worksheets. How would I go about doing so?
    Last edited by Lizzietish11; 03-19-2009 at 01:38 PM. Reason: solved

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Master and slave workbooks

    Is there any way to determine what new rows were added in the slave files like a date field in some column? If not, you will need to add them all and then run a macro to delete duplicate rows.

    Would the master be in that network folder?

  3. #3
    Registered User
    Join Date
    01-28-2009
    Location
    New York, USA
    MS-Off Ver
    Excel 2007
    Posts
    46

    Re: Master and slave workbooks

    There is no way to determine new rows.

    All the files will be in the same network folder

  4. #4
    Forum Contributor Tarball's Avatar
    Join Date
    04-21-2007
    Location
    Atlanta, GA
    Posts
    166

    Re: Master and slave workbooks

    I have done something similar to this in concept. One way you can identify the new rows is to "touch" them by adding something as simple as a date/time to a new column in each row that gets processed.

    You will of course have to coordinate with your users - Use a column that is way off of the usable range. In Excel 2007 this is easy as you can go out say 5000 columns to the right and tag each row processed.
    Reach me at excel_help at bellsouth dot net

  5. #5
    Registered User
    Join Date
    01-28-2009
    Location
    New York, USA
    MS-Off Ver
    Excel 2007
    Posts
    46

    Re: Master and slave workbooks

    it's possible but I would still need a way to find all the cells that are tagged in each individual workbook and paste them all into one consolidated tab on the master sheet.

  6. #6
    Forum Contributor Tarball's Avatar
    Join Date
    04-21-2007
    Location
    Atlanta, GA
    Posts
    166

    Re: Master and slave workbooks

    I would probably take a look at processing rows/columns instead of cells. And I would also look at collecting the data first (use a temp workbook or sheet). Collect the data and then process from the temp workbook or sheet. You can also simply collect a copy of their workbooks and keep them as a reference.

    You will also have to be able to coordinate when you run your macros to ensure that your users have updated their sheets and are ready for you to take the data.

    There is a lot to think about here but it can be done.

  7. #7
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Master and slave workbooks

    I did not address the duplicate issue. Play this from a backup of your master.

    Another method to eliminate duplicates might be to import the data for each slave to a sheet. If each slave has unique id's, you can just eliminate the duplicates after each run of the macro below.

    With alot of data, I would recommend regular backups of the master. Put this in a Module. Edit the paths in GetMySlaveData as commented as play it.
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    01-28-2009
    Location
    New York, USA
    MS-Off Ver
    Excel 2007
    Posts
    46

    Re: Master and slave workbooks

    Hi Kenneth,

    Each workbook that I am copying from will not have duplicate info; I just don’t want to write over the info pasted from each workbook. Duplicate info can exist. I plan to "re-run" the master workbook at the end of each quarter so the previous spreadsheet will be wiped out and the new info will replace it.

    I am still a beginner in editing macros. Would you be able to help me edit the paths?

    S:\Production\Annual Strategies is the folder in which all 13 files are located (12 individual slave files and 1 master file)

    Each slave file is named "TYLY-season-category" ex: TYLY-FALL 09-M DENIM

    The twelve categories are
    M DENIM
    M KNITS
    M GRAPHICS
    M SWEATERS
    M WOVENS
    M ACCESSORIES
    W DENIM
    W KNITS
    W GRAPHICS
    W SWEATERS
    W WOVENS
    W ACCESSORIES

    The master workbook is named "LYTY – Recap"

    For each slave workbook I need the “LY DATA” tab to be copied and pasted into the “LY data” tab in the master.

    I appreciate everything you’ve advised so far and this may be out of my level of understanding so if it is too complex for me I understand.

  9. #9
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Master and slave workbooks

    Then put all of my code in the master workbook's Module and it should do what you want.

    You can go to the link at vbaexpress and drag the SpeedUp module from that workbook to your master. Or, for now, comment out the SpeedOn and SpeedOff lines.

    Change this:
    Please Login or Register  to view this content.
    to:
    Please Login or Register  to view this content.

    You said all the sheets are sheet index 1 so the names are not important.

    While some macros look complicated, some look that way to help avoid errors.

  10. #10
    Registered User
    Join Date
    01-28-2009
    Location
    New York, USA
    MS-Off Ver
    Excel 2007
    Posts
    46

    Re: Master and slave workbooks

    I am getting a runtime error '91'

    "object variable or with block variable not set "

    when i opened debug the below is what was highlighted

    'Close the slave workbook if it was not already open
    If slaveOpen = False Then slaveWB.Close False

  11. #11
    Registered User
    Join Date
    01-28-2009
    Location
    New York, USA
    MS-Off Ver
    Excel 2007
    Posts
    46

    Re: Master and slave workbooks

    also if there are two tabs in the slave workbooks and I need to run a separate master file to grab all the info in the second tab what would i change in the macro to pull that information

    One tab is this year info and the other tab is last year info. I need the info on seprate tabs but in the same master file

  12. #12
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Master and slave workbooks

    Did you copy all of my code? Option Compare Text, makes it compare text where "Cat"="CAT".

    Step through your code with F8 so that you can see what is happening. Hover the cursor over variable names to see what they resolved to.

    We can always fix it to do additional tasks but it is best to get this one working first. It is a simple matter.

  13. #13
    Registered User
    Join Date
    01-28-2009
    Location
    New York, USA
    MS-Off Ver
    Excel 2007
    Posts
    46

    Re: Master and slave workbooks

    I copied it exactly, It doesnt appear to be finding the slave workbooks in the folder. Is there something I am missing? do i need to change anything in the individaul workbooks so the macro can define them?

    I still hit a runtime error at the same spot when checking with F8

  14. #14
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Master and slave workbooks

    You did not change the FilePath?

    If debug is bugging you, add this after the Do:
    Please Login or Register  to view this content.
    After you play it, it will show the filenames in the FilePath's folder in VBE's Immediate window.

  15. #15
    Registered User
    Join Date
    10-16-2009
    Location
    Lisbon, Portugal
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Master and slave workbooks

    Hi there I need to do the same master slave relation and I've tried this example but keep having the same error reported:

    I am getting a runtime error '91'

    "object variable or with block variable not set "

    when i opened debug the below is what was highlighted

    'Close the slave workbook if it was not already open
    If slaveOpen = False Then slaveWB.Close False

    Any idea on how to solve it?

    Thanks
    David

  16. #16
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Master and slave workbooks

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread.
    Hope that helps.

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

    Free DataBaseForm example

Closed 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