+ Reply to Thread
Results 1 to 34 of 34

Macro to import data from another workbook

  1. #1
    Forum Contributor
    Join Date
    08-15-2015
    Location
    India
    MS-Off Ver
    Office 2016
    Posts
    227

    Macro to import data from another workbook

    Hi all,

    i am creating data workbooks for each product with its technical specifications like weight of the product and different materials used, and based on the specifications, the price of the product changes.

    Now if i put all the product details in one workbook, the workbook becomes more than 100 mb, so i have to create new workbooks.

    Now since the rates of product material keeps on changing i need to update all the sheets to get the value of each product right.

    Is it possible where i create a master worksheet and can call for product details from other workbooks, based on the name of the product, without opening the source workbook.

    Please note the technical details of the product dont change and all products have unique codes.

    Any help on this to get me started will be a huge time saver.

    Regards

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Macro to import data from another workbook

    1. You can use vlookup to do that. Vlookup can look in a separate workbook. Just remember that if you separate the two after that, you'll have broken links. (You can copy and paste before the separation to preserve values.)

    2. You can write a macro to import the values.
    David
    (*) Reputation points appreciated.

  3. #3
    Forum Contributor
    Join Date
    08-15-2015
    Location
    India
    MS-Off Ver
    Office 2016
    Posts
    227

    Re: Macro to import data from another workbook

    Can u please help with the macro??

  4. #4
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Macro to import data from another workbook

    Please upload a sample workbook WITH sample data.

  5. #5
    Forum Contributor
    Join Date
    08-15-2015
    Location
    India
    MS-Off Ver
    Office 2016
    Posts
    227

    Re: Macro to import data from another workbook

    Have attached the master workbook, where i want the data based on the product code, and the data sheet containing details of the product.
    For ease of understanding i have colored the data and the place in master where i want the data.Please ignore cells with yellow color as they are not to be changed
    Attached Files Attached Files

  6. #6
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Macro to import data from another workbook

    Ok, explain how you want this to work.

    You select a value in B3. (I assume the product codes are already loaded.) Once you exit the cell, the colored cells (non Yellow) are populated from the data sheet?

    And do you want to bring the whole group in, or just a single entry?
    Last edited by Tinbendr; 01-02-2016 at 12:20 PM.

  7. #7
    Forum Contributor
    Join Date
    08-15-2015
    Location
    India
    MS-Off Ver
    Office 2016
    Posts
    227

    Re: Macro to import data from another workbook

    Hi,apologies for the delay in reply, my net was down,

    want to get the whole group based on the product code, also will i have to save all data sheets in one folder for the data to be fetched ??

    For your reference am sending u an output master, which shows the data imported from the data file.

    Regards
    Attached Files Attached Files

  8. #8
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Macro to import data from another workbook

    OK Here is the code. I'll upload the master file as well.

    You'll need to edit the path of the data.xlsx location.

    In the Master!Data sheet code page.
    Please Login or Register  to view this content.
    Add a module and insert this.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    08-15-2015
    Location
    India
    MS-Off Ver
    Office 2016
    Posts
    227

    Re: Macro to import data from another workbook

    I dont want my data in the yellow cells to clear as they have formulas

  10. #10
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Macro to import data from another workbook

    Hmm. So they do.
    Change to this.
    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    08-15-2015
    Location
    India
    MS-Off Ver
    Office 2016
    Posts
    227

    Re: Macro to import data from another workbook

    Thanks for the update, i will make the changes and revert back,

    one more thing is it not possible to have the path set for the data using a macro.

    Meaning i need not go to the vba code, but by running the macro i can specify the path of the data file,

    this should be done whenever i want to change the path of the data folder, if i dont change it, then the path i lasted selected will remain.

  12. #12
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Macro to import data from another workbook

    I can change it to where it ASKS where the file is. But it will do this every time.

    Maybe we could set the path the first time the macro runs. We can store the path/filename somewhere. Then whenever the macros runs after that, we just check the location to see if the file is still there. If it is, we continue on, else it stops and asks for it.

  13. #13
    Forum Contributor
    Join Date
    08-15-2015
    Location
    India
    MS-Off Ver
    Office 2016
    Posts
    227

    Re: Macro to import data from another workbook

    Yup, asking for the file every time does not make sense,

    your second option should do the trick, where first up it will ask for a path, and next time when the macro is run

    and it does not get the path, it will ask for the path.

    But again would want the macro to allow us to decide the path without going into the vba code mode.

  14. #14
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Macro to import data from another workbook

    Ok, try this.

    If you NEED to edit the path for some reason, I store the path in the Subject field of the document properties. (File->Info-(scroll to bottom -Show All Properties) Just clear out the field and rerun the macro. It should ask again the the path to the file.

    The only thing about this is that it doesn't prevent someone from selecting the wrong file. In that case, the macro will likely halt on an error.

    If you want to add that protection, I suggest we add a phrase to the subject field of the dataset file. We can check for that value to discern if the correct dataset was selected.
    Please Login or Register  to view this content.

  15. #15
    Forum Contributor
    Join Date
    08-15-2015
    Location
    India
    MS-Off Ver
    Office 2016
    Posts
    227

    Re: Macro to import data from another workbook

    Your present code has that protection??

  16. #16
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Macro to import data from another workbook

    It does not. We'll have to add that if you like.

  17. #17
    Forum Contributor
    Join Date
    08-15-2015
    Location
    India
    MS-Off Ver
    Office 2016
    Posts
    227

    Re: Macro to import data from another workbook

    It would be great if u can add that too.

  18. #18
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Macro to import data from another workbook

    OK, first, are you the author of the dataset? If not, can you get the author to put a specific word in the Subject field of the file?

    What keyword/token/password do you want to use for the dataset.xlsx file? It doesn't have to be anything sophisticated. But it will be hard coded in the code. So, if you decide to change it in the dataset, you'll have to update it in the code as well. And anyone who has a little code experience will be able to change it. But then, this is not like password protection. This is just a general test for the correct file.

  19. #19
    Forum Contributor
    Join Date
    08-15-2015
    Location
    India
    MS-Off Ver
    Office 2016
    Posts
    227

    Re: Macro to import data from another workbook

    i am the author, u can put in %NirmALL99

  20. #20
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Macro to import data from another workbook

    Be sure to add the keyword to the dataset subject field.
    Please Login or Register  to view this content.

  21. #21
    Forum Contributor
    Join Date
    08-15-2015
    Location
    India
    MS-Off Ver
    Office 2016
    Posts
    227

    Re: Macro to import data from another workbook

    I will be having 1 workbook for each product code, so i have to specify the folder where the data workbooks are stored????

  22. #22
    Forum Contributor
    Join Date
    08-15-2015
    Location
    India
    MS-Off Ver
    Office 2016
    Posts
    227

    Re: Macro to import data from another workbook

    Hi, ur old code works fine in your masterdata, but cant figure out where i put my path for data in the new vba code??

  23. #23
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Macro to import data from another workbook

    You will just have to navigate each one the first time.

  24. #24
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Macro to import data from another workbook

    Quote Originally Posted by Nirmall View Post
    Hi, ur old code works fine in your masterdata, but cant figure out where i put my path for data in the new vba code??
    If you're talking about the data file keyword, that's all you have to key in manually the first time.

    Open the data file. Select File-Info (scroll to bottom on right) select all Properties- Type in the keyword (%NirmALL99) in the Subject field. Save.

    Redistribute the data file along with new Master. When the new Master is opened, the user will have to navigate to the data file, which will include the keyword.

  25. #25
    Forum Contributor
    Join Date
    08-15-2015
    Location
    India
    MS-Off Ver
    Office 2016
    Posts
    227

    Re: Macro to import data from another workbook

    I did, have attached a screen shot of whats happening
    Attached Images Attached Images

  26. #26
    Forum Contributor
    Join Date
    08-15-2015
    Location
    India
    MS-Off Ver
    Office 2016
    Posts
    227

    Re: Macro to import data from another workbook

    Still not working, can u please help

  27. #27
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Macro to import data from another workbook

    OK, you will have to delete the path from the Master file Subject line until you can read the data file for the first time after adding keyword.

  28. #28
    Forum Contributor
    Join Date
    08-15-2015
    Location
    India
    MS-Off Ver
    Office 2016
    Posts
    227

    Re: Macro to import data from another workbook

    not working can u please edit the code and send it for the master file?

  29. #29
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Macro to import data from another workbook

    Here ya go.
    Attached Files Attached Files

  30. #30
    Forum Contributor
    Join Date
    08-15-2015
    Location
    India
    MS-Off Ver
    Office 2016
    Posts
    227

    Re: Macro to import data from another workbook

    Sorry but still am getting the same message cant we do away with the password?

  31. #31
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Macro to import data from another workbook

    It's Post #14.

  32. #32
    Forum Contributor
    Join Date
    08-15-2015
    Location
    India
    MS-Off Ver
    Office 2016
    Posts
    227

    Re: Macro to import data from another workbook

    You have been very patient, thanks a ton,

    1 last request,

    can u send me a screenshot for this

    If you NEED to edit the path for some reason, I store the path in the Subject field of the document properties. (File->Info-(scroll to bottom -Show All Properties) Just clear out the field and rerun the macro. It should ask again the the path to the file.

  33. #33
    Forum Contributor
    Join Date
    08-15-2015
    Location
    India
    MS-Off Ver
    Office 2016
    Posts
    227

    Re: Macro to import data from another workbook

    Got it amillion thanks, u are jus too good

  34. #34
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Macro to import data from another workbook

    Here's a snapshot for anyone else.
    !Untitled.png

+ 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 import data to another protected workbook
    By Dimy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-25-2015, 02:31 AM
  2. Macro to import data from one workbook into another & saving
    By badlydrunkboy in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 07-14-2014, 01:29 PM
  3. [SOLVED] How do I import data from spreadsheet to macro enabled workbook on seperate spreadsheets ?
    By vyokus in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 01-03-2014, 06:53 PM
  4. VBA Macro code - import data from another workbook (VLOOKUP)
    By madi1004 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-17-2013, 03:27 PM
  5. Modify exiting Macro Export data from multiple workbooks and Import into 1 Master workbook
    By SerenitynWisdom in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-24-2013, 11:55 PM
  6. [SOLVED] Import data from an excel workbook to another workbook without manually selecting
    By rmachbitz in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-15-2013, 02:27 PM
  7. Macro to Import Data from Closed Workbook to CSV File
    By groundin in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-06-2013, 09:39 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