+ Reply to Thread
Results 1 to 12 of 12

[Solved] Pull or Push data from one workbook to another

  1. #1
    Registered User
    Join Date
    02-03-2010
    Location
    Holland
    MS-Off Ver
    Excel 2003
    Posts
    12

    [Solved] Pull or Push data from one workbook to another

    Hi!

    I'm looking for something that will be able to push or pull data from a workbook (named "Personen - test.xls" = persons) to an other workbook (named "Personen per maand.xls" = persons/month). In attached documents i tried to make clear (sorry, it's in dutch) what i would like to do. In English; the marked data in "Personen - test.xls" should automatically be shown in the marked area in "Personen per maand.xls". I think the biggest problem is the fact that "Personen per maand.xls" is a standard-document which should be filled -time after time- with many different data's from several "Personen - test.xls" documents. These documents are all named different, the data is always given in the same way. So in my opinion i should make something where i can tell excell which document to use and something i can tell where to put the data. But i really don't know how to do this...

    Hopefully my English is not too bad to understand what i would like to do...

    Brigitte
    Attached Files Attached Files
    Last edited by Brie; 02-17-2010 at 04:59 AM. Reason: [Solved]

  2. #2
    Forum Contributor sauerj's Avatar
    Join Date
    11-11-2009
    Location
    Lafayette, IN
    MS-Off Ver
    Excel 2019
    Posts
    163

    Smile Re: Pull or Push data from one workbook to an other

    Hello,
    • Attached is an edited version of your Personen-text.xls file. In this file, I built a macro that might work for you.
    • I also edited Personen per Maand.xls as I added data to all three Blad sheets for test purposes. These sheet additions (to Blad2 and Blad3) are the only changes I did on this file.
    1. Open "Personen-text.xls". Then, open the VB Editor and see the new macro in module z_CopyMacro. The macro is called: CopyToPersonen.
    2. Look thru details of this macro. Change the file names so to exactly match your names. Read top comments that explain how to use the macro. If you don't like what I have, make the changes necessary to get it closer to what you had in mind.
    3. Go to the "Personen per Maad.xls" file and input dummy values in the cells (all 3 sheets if you want). Then, go back to "Personen.xls" and RUN the macro. I also setup the macro so you can use the shortcut keys "Cntrl + Shift + P". It should copy the cells values from "Personen per Maad.xls" to "Personen.xls" (or whatever names you have).
    4. Edit to suit your needs. NOTE: Some of the forum gurus might have much better ways of doing this, depending on your exact needs. But, I hope I helped you get started in some way.
    5. Good luck and best regards.
    ... sauerj
    Attached Files Attached Files

  3. #3
    Valued Forum Contributor
    Join Date
    06-16-2006
    Location
    Sydney, Australia
    MS-Off Ver
    2013 64bit
    Posts
    1,394

    Re: Pull or Push data from one workbook to an other

    This is actually not that hard. Just open both workbooks.
    1. Click in cell B2 on sheet "Aantal personen per maand"
    2. press the = button on your keyboard
    3. then while the formula bar is still waiting for the formula, click on the other workbook and click in the cell that contains the source data.
    4. Make sure you remove the absolute references (ie delete the $ signs from $B$3 so you are left with B3)
    5. Then copy the formula down to complete the 5 people.

    Save the sheet and close. Next time you open it, Excel will prompt you if you want to update the links, or you can do this manually. I don't have Excel 2003 anymore but I think it is in the file menu. When you find it, there will be an option to change the source file. Just select the new file with the new name.

    I have a short video I can send you if you send me your email address. don't post it here, send me a private message.

  4. #4
    Forum Contributor sauerj's Avatar
    Join Date
    11-11-2009
    Location
    Lafayette, IN
    MS-Off Ver
    Excel 2019
    Posts
    163

    Smile Re: Pull or Push data from one workbook to an other

    Hello, Mallycat's approach is definitely the most straightforward. If the "Personen per maad.xls" files never change name or location, and the employee's always use the same "Personen per maad.xls" files, then Mallycat's approach will ALWAYS work great everytime you open "Personen.xls" and update links.
    But, as a follow-up to the macro idea, I thought of a few tweaks to what I initially sent you. So, I'm sending updated versions of both files. The main change was saving all of the important variables at the top of the macro making it easier to change the variables in 1 place.
    This macro approach is deficient (compared to Mallycat's better link approach) in that you HAVE to open the "Personen per maand.xls" files for this macro to work. For Mallycat's idea, you don't. Just open "Personen.xls" ONLY and it will automatically get the input data from all of the "Personen per maand.xls" files even if they are closed (once you select UPDATE LINKS) and "POOF" you are done!
    ... Take care, sauerj
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    02-03-2010
    Location
    Holland
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Pull or Push data from one workbook to an other

    Hi Mallycat and Sauerj,

    I tried the codes, but this didn't work out for me on the right way...

    I was trying something else (simply by recording a macro) and I think I am on the right track by now. But the macro is not acting like the way I expected it to act. It gives an error, which causes that just "imported" sheets are not filled with data from the opened file. I do not understand why this does not work ...
    Can someone help me with this?

    In this macro I opted for some names, but it is intended that the files may have different names, is here existing a simple code for?

    Attached files will make clear what I'm trying to write down, I expect.
    The point is that I work from one of the various files (eg "Personen X - test.xls" or "Personen Y - test.xls"), subsequently add the sheet of "personen per maand - test" and should the data from the opened file (personen X or Y or Z or etc.) automatically be inserted, due to links between cells. This could very easily, since these are in the same workmap, I thought. But here is the macro down ...
    The last document you can see on the attached files-list is "totaal" and that's what I intended to make... (the total-file)

    Do you have tips / ideas?

    Greetings Brigitte
    Attached Files Attached Files

  6. #6
    Forum Contributor sauerj's Avatar
    Join Date
    11-11-2009
    Location
    Lafayette, IN
    MS-Off Ver
    Excel 2019
    Posts
    163

    Smile Re: Pull or Push data from one workbook to an other

    Brie, I have studied your files & macro in detail. I am confused. It is not clear what you are after. Your code seems to do exactly opposite what I originally thought you were wanting. I thought you were trying to copy data from the broken-up tables to the single unbroken table. Your macro does the opposite. The only way I can be of any help is if you re-post with clearer instructions, such as ...
    1) Start by showing the INPUT file BEFORE making any changes,
    2) Then, show the file you want to copy data TO, BEFORE making any changes.
    3) Explain the SOURCE location of data to be copied FROM, and TARGET location where data is to be copied TO,
    4) Then, include a FINAL file or files showing correct formulas in their proper place that give you the correct results. Manually put these formulas in these FINAL file(s), so they are EXACTLY as they should be, not by a macro that may be not working correctly.

    With these instructions, someone should be able to get you code to do this job, or at least get you better started.... Best Regards, sauerj

  7. #7
    Registered User
    Join Date
    02-03-2010
    Location
    Holland
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Pull or Push data from one workbook to another

    Sorry, English is not my native language, perhaps causing some confusion ...
    I find it quite difficult to indicate how I try to write the macro. The way you like it to show is a lot clearer, so here we go:

    1) open the excel file (file is always another - each with a different name, eg "personen X - test" or "personen Y - test)
    2) press the macro button (I alreaddy made this, don't know if it's possible to see it in the files I already attached):
    3) The macro copies the parent-file ( "personen per maand - test") to the already opened file (depending on which file you've already opened - "personen X - test" or "personen Y - test).
    4) Close the parent-file
    5) the list per month divided as shown in "Personen per maand - test" is filled with data from the previously opened file ( "personen X - test" or "personen Y - test") - where for example "Personen X - test" should be linked to cell B2 in cell B3 "Personen per maand - test".
    6) by copying the reference down the line disappears, that I'll draw through the line style back again.
    7) Save file as ... (I prefer doing this by using a pop-up screen)


    This way I have the macro actually in my mind.

    Hopefully I have something like this clearly able to explain.
    If that is not the case let me know.

    Thanks so much for your time.
    best regards,

  8. #8
    Forum Contributor sauerj's Avatar
    Join Date
    11-11-2009
    Location
    Lafayette, IN
    MS-Off Ver
    Excel 2019
    Posts
    163

    Smile Re: Pull or Push data from one workbook to another

    Brie,
    * Your step-by-step instructions match your macro exactly. And, when I run your macro, I get NO errors until it hits the very last line; got an error on the SaveAs line as it was trying to save file when the hard-coded filename already existed. ... NOTE: To get your macro to work for me, I had to edit the file PATHS so to match where I saved files on my PC, but I assume you have the right paths (for your PC) in your macro.
    * I see that you also want macro to provide pop-up screen to prompt user for new filename (this would be a good thing to do). As you know, macro, as is, does NOT do this. So, to get a pop-up screen that works in conjunction with the last SaveAs line, then replace your last SaveAs line with the following two lines:
    Please Login or Register  to view this content.
    Once I did this, I didn't get any errors. Make this above code change; and try it. Then, if you still get errors, use the Breakpoints (under Debug Menu) to stop the code at key steps so that you can watch what it is doing (jumping back & forth between VB and Excel to watch step-by-step effect to Worksheet). Or, use the F8 button to step thru it 1 step at a time. If you still are stumped, then write back describing EXACT line of error, and what the error alarm message exactly is.
    NOTE: If you insert code in your note, then remember to use CODE TAGS to properly format it. If you don't know what I mean by this, please go to Forum Rules and read the section on Code Tags. This is important for getting good & fast help! ... Good luck, sauerj
    Last edited by sauerj; 02-11-2010 at 12:00 AM.

  9. #9
    Registered User
    Join Date
    02-03-2010
    Location
    Holland
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Pull or Push data from one workbook to another

    Hi Sauerj,

    This works perfect! Thanx! I've even expanded the macro, making it possible to convert the csv-file to the list.

    The only problem I have to solve now is that the macro is used only for this file. Actually I need to change anything, so it does not matter which file I open. So the macro works in all cases.

    My macro code (by now) is:

    Please Login or Register  to view this content.
    The line where it goes wrong is:
    Sheets("Personen X - test1").Select
    But I think this will give some problems too:
    Sheets("Personen X - test1").Name = "CSV"
    Sheets("Blad1").Copy Before:=Workbooks("Personen X - test1.csv").Sheets(1)
    cause for now the Workbook is called for example "Personen Y - test1.csv"

    Is the solution to this problem easy to write?
    Or can someone explain to me what terms are used for this? I've already searched around but I think I'm looking at the wrong names ...

    I attached the files - usefull for trying my code I think
    Two files are zipped, because it wasn't possible to upload CSV-files.

    Best regards,

    Brie
    Attached Files Attached Files

  10. #10
    Forum Contributor sauerj's Avatar
    Join Date
    11-11-2009
    Location
    Lafayette, IN
    MS-Off Ver
    Excel 2019
    Posts
    163

    Smile Re: Pull or Push data from one workbook to another

    Brie, I made changes to macro that, I think, makes it do what you want.
    1) Save attached 4 files to your "C:\Documents and Settings\brigitte\Bureaublad\Test\" folder.
    2) Open "Personen_X_Start(Test1).xls" and Open "Personen_X_CSVData.txt"
    3) Swipe ALL text in the TXT file. And, copy ALL of this into clipboard (Ctrl + C).
    4) Go to "Personen_X_Start(Test1).xls" and Run macro "Overzicht_maken_per_afdeling".
    5) It will prompt you for New file name. For now, give the new file name "Personen_X_Finish(Test1).xls", which is one of the 4 files I included. It will tell you that this file already exists, and ask you to confirm saving over it. Answer 'Yes'.
    6) Macro will open "Personen per maand - Test.xls" (also in this folder). Copy Blad1 sheet, and do all of the formula additions. At end, it will re-save "Personen_X_Finish(Test1).xls". When done, you should only have "Personen_X_Finish(Test1).xls" & "Personen_X_CSVData.txt" open. ... "Personen_X_Start(Test1).xls" & "Personen per maand - Test.xls" do not get changed in macro.
    7) Hopefully this is close to what you want. Edit as necessary.

    * Use 'Step Through' to Debug (F8). Read Excel HELP carefully. Look over macro and read my comments carefully. ... In the last year, I have been working VERY hard on Excel VB for work reasons (after touching it on & off for the last 5 years). I am ONLY now starting to get the hang of it. I have found it very frustrating throughout the whole last year; seems to have SO many different commands, etc.
    * My POINT: About a month ago, I finally went out and bought a $25, 300page book on Excel VBA Programming. I should have done that months ago. ... You should browse thru the selections at a local book store. Make sure it is easy to understand. You don't need a real HUGE or super fancy book, just one that covers the main basics. I highly recommend this.
    * If this solved it (I hope), please EDIT your first note, GO ADVANCED, and changed PREFIX to [SOLVED]. Also, Please "tip my scales" if solved. ... Thanks, sauerj
    Attached Files Attached Files
    Last edited by sauerj; 02-12-2010 at 01:49 AM. Reason: Updated with new post & attachments

  11. #11
    Registered User
    Join Date
    02-03-2010
    Location
    Holland
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Pull or Push data from one workbook to another

    Yes! I've found it!

    Saurj sorry, I've looked at your solution, but while I had two files open per se, one copy to the clipboard and the other I would again use the clipboard to fill it. Stubborn maybe, but I'm once again went looking for what I had in mind ... I have some rules changed and now it works for any document with the same format. Great!

    HTML Code: 
    For some reason I wasn't able to mark the lines in blue (or other color), but the lines are shown at the first part;

    Dim myOriginalFileName As String
    myOriginalFileName = ActiveWorkbook.Name

    Dim myOriginalSheetName As String
    myOriginalSheetName = ActiveSheet.Name

    And then its possible to use the name of the workbook/sheet everywhere.

    I now have some nice things to expand, I'm starting to really like it, haha!

    Best Regards,

    Brigitte

  12. #12
    Forum Contributor sauerj's Avatar
    Join Date
    11-11-2009
    Location
    Lafayette, IN
    MS-Off Ver
    Excel 2019
    Posts
    163

    Re: Pull or Push data from one workbook to another

    Brie, Good to hear that it is coming together for you. If this Post is generally solved, then please EDIT 1st post to CHANGE Prefix to SOLVED. Read FAQs for further instructions. ... Take Care, sauerj

+ 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