+ Reply to Thread
Results 1 to 9 of 9

Macro to pull data from another workbook.

  1. #1
    Registered User
    Join Date
    04-17-2013
    Location
    london
    MS-Off Ver
    Excel 2002
    Posts
    49

    Macro to pull data from another workbook.

    I would like to create a macro that pulls data from 1 sheet into a new workbook from another workbook (to certain columns only e.g a,b,e to be copied and pasted into a,b,c), however the workbook is not static. I have a workbook that is used every week and the filename is different every week. It is saved for that particular week when it is used for example workbook19082013, workbook26082013 etc.
    Is there a code I can use when linking the two workbooks( in order to pull/paste data from the weekly workbook to another one) that is not fixed/static to the workbook name. Is there a code for using "current workbook that is open" or something similar?
    Anybody know of an alternative?

    Hope this makes sense!

    Thanks in advance.
    Last edited by cherryt; 08-27-2013 at 08:41 AM. Reason: requirements changed

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Macro to pull data from another workbook.

    Cherry.

    Lets start with the Excel worksheet copy move function and see where where that takes us.

    Open your weekly workbook

    Right Click on the tab at the bottom of excel for the worksheet that you are interested in.

    Select "Move or Copy"

    A small window will open.

    At the top is a list box It shows the name of your work sheet. Click on that and select "New Book"

    At the bottom is a check box that says "Create Copy" Click on that so it becomes a Tick.

    New Click on Ok.


    Now is that what you need? If not why not? Please post your comments so I can try and help you.

  3. #3
    Registered User
    Join Date
    04-17-2013
    Location
    london
    MS-Off Ver
    Excel 2002
    Posts
    49

    Re: Macro to pull data from another workbook.

    Hi mehmetcik, thanks for responding. The reason why I'm not using the simple move and copy is because some columns/row of data won't be copied over.
    I have amended my first post to reflect this.
    thanks.

  4. #4
    Registered User
    Join Date
    04-17-2013
    Location
    london
    MS-Off Ver
    Excel 2002
    Posts
    49

    Re: Macro to pull data from another workbook.

    This is the code I have so far.
    Both workbooks have the same sheet name. The workbook the data is being pasted from will not have the same name each week. Assume both workbooks will be/are open.
    The code is for the workbook that the data will be pasted into.
    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Macro to pull data from another workbook.

    Ok

    I think that your copy routine will work with a couple of changes.

    Delete this row:-

    Please Login or Register  to view this content.
    You are not using it in your code and you are confusing a worksheet with a workbook.

    Change this formula:-

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

    Please Login or Register  to view this content.
    In my test this then worked without corrupting my formulae.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    04-17-2013
    Location
    london
    MS-Off Ver
    Excel 2002
    Posts
    49

    Re: Macro to pull data from another workbook.

    Hi Mehmetcik,
    Thank you so much for the code. I'm missing the code for the macro to run without giving the file name to an already open workbook. I would like to copy columns from another workbook, which isn't going to have a fixed name but will be open hence why I need the code to use the workbook that is currently open. The workbook that the columns will be pasted into is called summary template and to confuse matters even more the other workbook sheet has the same name.
    Last edited by cherryt; 08-28-2013 at 04:03 AM.

  7. #7
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Macro to pull data from another workbook.

    This code works for me You need to change
    Please Login or Register  to view this content.
    to be your master file name:-

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    04-17-2013
    Location
    london
    MS-Off Ver
    Excel 2002
    Posts
    49

    Re: Macro to pull data from another workbook.

    Eh? I'm confused by your suggestion. The workbook that data is being copied from should also be open. I want to avoid stating the name of the book because it will change weekly. The workbook it is being pasted into, the name won't change i.e. will stay book3.

  9. #9
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Macro to pull data from another workbook.

    Lol.

    You run the macro while the new workbook is open and active. [ Make sure that the new one is active by opening that last, or clicking onto it ]

    Then the macro will use the command:-
    Please Login or Register  to view this content.
    to learn its name.

    Your master workbook must also be open. or you should modify the macro to open it.

+ 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. [SOLVED] Macro to pull data from another workbook
    By logesh excel in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-07-2013, 02:24 PM
  2. Replies: 0
    Last Post: 04-03-2013, 01:58 AM
  3. [SOLVED] Macro to pull out data from specific cells and save it in another workbook
    By kittu55 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 02-02-2013, 11:02 AM
  4. [SOLVED] Master workbook to pull data from second workbook into seperate sheet
    By djm601 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-16-2013, 09:24 AM
  5. Macro to pull data from outside workbook and determine maximum value
    By OSUBigToe in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-25-2012, 01:20 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