+ Reply to Thread
Results 1 to 8 of 8

VBA Macro to Copy Data from Another Workbook in Excel

  1. #1
    Registered User
    Join Date
    08-08-2020
    Location
    Frankfurt
    MS-Off Ver
    2013
    Posts
    17

    Lightbulb VBA Macro to Copy Data from Another Workbook in Excel

    Hello Everyone,

    I would like to raise the following question regarding copying data from workbooks. In general I know the way to write a VBA code in order to copy data from one workbook to another when I know the name of the "source workbook".
    However, I am downloading data from Bloomberg on a weekly basis for a project which means that each week i have to copy and paste the new data from the bloomberg workbook to the workbook that I am working on. So in each week I have around 10-15 new data. However, it could be that the name of the workbook from where I get the data is not the same every time. Is it possible to create a VBA code that always imports data from a workbook independent of its name?
    Thanks in advance!

  2. #2
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,122

    Re: VBA Macro to Copy Data from Another Workbook in Excel

    Download to where...One folder which houses Source Book & downloaded file?
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  3. #3
    Registered User
    Join Date
    08-08-2020
    Location
    Frankfurt
    MS-Off Ver
    2013
    Posts
    17

    Re: VBA Macro to Copy Data from Another Workbook in Excel

    Dear Sintek,
    Thanks for the response. I will explain it in more detail. Imagine that I have file1 and file2 (taken from Bloomerg) both open. What I am saying is that I know how to write a macro code in order to import the new data from file 2 to file 1. However, each time the file that I download from bloomberg will have a different name imagine for instance file(3). How can I write a code that always imports the new data from the bloomerg file to file 1 independent of bloomberg file's name?

  4. #4
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,122

    Re: VBA Macro to Copy Data from Another Workbook in Excel

    So...where are you downloading then to...
    Are you storing them in a specific folder which will enable you always to have your Source File and the newly downloaded file...
    This way you will always only have two files...One which you know the name of an the other irrespective of name...

  5. #5
    Registered User
    Join Date
    08-08-2020
    Location
    Frankfurt
    MS-Off Ver
    2013
    Posts
    17

    Re: VBA Macro to Copy Data from Another Workbook in Excel

    Indeed the main file is always saved on a specific folder however the bloomberg "new file" not. The following is the code that I am using. Imagine that my main file is "regression" and I want to get data from "game" which works fine. However imagine that next week the file "game" will be named "wardrobe", so my question is how to automate the code in order to copy and paste the data from Bloomberg independent of their name.

    Please Login or Register  to view this content.
    Last edited by theocharis; 08-08-2020 at 05:26 AM.

  6. #6
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,122

    Re: VBA Macro to Copy Data from Another Workbook in Excel

    Indeed the main file is always saved on a specific folder however the bloomberg "new file" not
    Not giving me a clear understanding of your process...
    this code you have supplied is obviously in a third workbook...As you are opening two alternate files...
    If you are making use of code to open files, you will need to know the path or name or you will have to search for a workbook with specific criteria...
    If you are manually opening both files and then running code you can check file names of open workbooks and then make use of this ...
    According to your code both are in same path...
    What code are you making use of to download bloomberg file?
    If manually, where are you saving it to?

    Also...Please take a moment to read our forum rules...here
    Your post does not comply with Rule # 2
    2. Programming code must be enclosed in code tags to improve readability. (A, Z)
    Please Login or Register  to view this content.
    So...Edit your post...Highlight the code and press the # button

  7. #7
    Registered User
    Join Date
    08-08-2020
    Location
    Frankfurt
    MS-Off Ver
    2013
    Posts
    17

    Re: VBA Macro to Copy Data from Another Workbook in Excel

    Apologies for the rule 2! I fixed it.

    I try once more in order to become more specific. I have a file named "credit spreads" which needs to be refreshed its week which means that I need each week to import some additional data. This file is saved on folder "economy". After that i go into bloomberg and search for credit spreads and after i find the ones that i need I export them into a new excel file named for instance "game" and saved on the folder "downloads". I don't want a code in order to open or close my files. What i need is to create a macro button based on a vba code and when i press it I want it to add the new values from the bloomberg file into the "credit spreads" file, but independent of the bloomberg file name because the name when I download it another time could be for instance "table". I want my code to be independent of the Bloomberg file name.

  8. #8
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,122

    Re: VBA Macro to Copy Data from Another Workbook in Excel

    No sorry I do not understand...
    Your initial code that you posted above...does not match the description you posted above...

    Perhaps someone else can understand your requirement...sorry for wasting your time...

    I suggest you explain step by step what your process is so that someone else is immediately able to assist...

    Such as ...

    I have a file named X which is found in this Path and houses the following code...123 code
    I now download a file from bloomberg and I save it in Y...this files name changes weekly...
    My code must obviously be able to find this file and open it to extract info into original X file...
    How can I access this file if I do not know its name...

    You still need a Path & still need to open this file....

+ 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. Excel Macro Copy Alph Numberic Data from a Closed CSV File to an Active Excel WorkBook
    By sanjaydutta20022 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-01-2016, 10:33 PM
  2. Use a macro to copy data from Outlook email to Excel workbook
    By Santhoshhrishi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-10-2015, 12:36 AM
  3. Excel Macro to copy data every 288th cell from another workbook
    By riajaravata in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-23-2015, 12:11 PM
  4. Excel - macro to loop through row data and copy cell to each worksheet in the workbook
    By swilson2006 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-21-2013, 07:54 AM
  5. Macro to copy specific cell data into a different excel workbook
    By Khanzaki in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-08-2013, 05:55 AM
  6. [SOLVED] Excel macro to search a particular workbook and copy data to consolidated
    By akhileshgs in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-11-2013, 10:34 AM
  7. To copy data from two different excel workbooks in a single workbook using macro
    By neha_gunaji in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-11-2012, 03:28 AM

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