+ Reply to Thread
Results 1 to 18 of 18

Combine different tables in one table from selected files

  1. #1
    Forum Contributor
    Join Date
    12-13-2012
    Location
    Italy
    MS-Off Ver
    Excel 2010
    Posts
    162

    Lightbulb Combine different tables in one table from selected files

    Hello everyone,

    I just need your help in making my macro code better to do it work like I need.

    My code
    Please Login or Register  to view this content.
    What actually does these code:
    1. it has to open the file from selected folder...name of the file is in cell B3
    2. select range and copy it
    3. past only values in the last empty row in column A of the origin workbook - OPS.xlms
    4. close the opened workbook.

    What should it do?
    I want that the macro stops if the file with the selected name does not exist - so if i write in B3 February (example) and file with these name does not exist in folder it displays msg box - file with these name doesn't exist and stop the macro.
    To sum values in the column E of the opened workbook and displays the result in a msg box or in a cell (B4) of origin workbook.


    I really don't know hot to set up the code that it will work like I want.

    Your help will be appreciated,
    forfiett
    Last edited by JBeaucaire; 02-17-2013 at 03:51 AM. Reason: Use CODE tags, not QUOTE tags.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Combine different tables in one table from selected files

    Assuming this macro is stored IN the OPS.xlsm workbook, maybe this:
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Contributor
    Join Date
    12-13-2012
    Location
    Italy
    MS-Off Ver
    Excel 2010
    Posts
    162

    Re: Combine different tables in one table from selected files

    Thanks for your help
    it is working good

    the only problem I am facing with is..

    error.png

    Is possible to disable these message?

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Combine different tables in one table from selected files

    Add this neart the top of your macro:

    Please Login or Register  to view this content.

    If that takes care of your original query, please select Thread Tools from the menu above and mark the thread as solved. Thanks.

  5. #5
    Forum Contributor
    Join Date
    12-13-2012
    Location
    Italy
    MS-Off Ver
    Excel 2010
    Posts
    162

    Re: Combine different tables in one table from selected files

    Thanks, it is working

    now I am facing one big problem...
    So..as I explained I have different folders containing a lot of files that some of them has to be merged in one file. Above opens only the file if the name completely match the value in cell B3.
    The problem consist in my colleagues that are saving them files with incorrect names..for example..February 13 i/o February...so the macro doesn't open some files (file with incorrect names).

    To avoid these problem I have one idea but with my "less" excel knowledge I don't know how to realize.
    It is possible that macro recognize all files in one folder (C:\Users\1) and display all names in message box with option to choose that you want to merge.

    Let me explain...I have 6 folders containing a lot of files..so the macro it has to display a msg box for each of these six folder..like on the bellow image..

    msg box.jpg

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Combine different tables in one table from selected files

    That macro had the fPATH hardcoded. Instead, how about a cell that let's you enter the folder? Then the macro cycles through ALL the files in that folder? Maybe?

  7. #7
    Forum Contributor
    Join Date
    12-13-2012
    Location
    Italy
    MS-Off Ver
    Excel 2010
    Posts
    162

    Re: Combine different tables in one table from selected files

    Yes, macro should not use the value in B3...instead of that I want that it displays all files in the folder and let to me (user) which file to use. ..and the same for all six folder.

    I think is easily to do the macro that to instruct (and bother.....) every day all may colleagues to save their files with correct names.

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Combine different tables in one table from selected files

    I was talking about letting them save the files with whatever names they want, then let the macro simply import all the sheets in that known folder one at a time and "do something specific" with that data, then repeat with the next file until all files are done, all at once.

    Then the files that folder are moved elsewhere so they don't get reprocessed later.

  9. #9
    Forum Contributor
    Join Date
    12-13-2012
    Location
    Italy
    MS-Off Ver
    Excel 2010
    Posts
    162

    Re: Combine different tables in one table from selected files

    Yes, good idea. But how to select witch workbook to import in the folder?

  10. #10
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Combine different tables in one table from selected files

    I'm suggesting we do them all. All that is needed is a full set of instructions of what is to be "done" with each file as it is imported. So far:

    1) Get filename from folder
    2) Open the file
    3) Copy the data and paste into master sheet
    4) Close the opened file
    5) Move the opened file to another folder
    6) ?? stuff do with data ??
    7) ?? save somewhere with some name ??
    8) Repeat steps above for each file in the folder

  11. #11
    Forum Contributor
    Join Date
    12-13-2012
    Location
    Italy
    MS-Off Ver
    Excel 2010
    Posts
    162

    Re: Combine different tables in one table from selected files

    Ok thanks for info

    1) Get filename from folder - and select witch file to use in these folder (only one file on one folder has to be used)..Six folders = six files
    2) Open the file
    3) Copy the data and paste into master sheet
    4) Close the opened file

  12. #12
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Combine different tables in one table from selected files

    Will the folder only have ONE file in it? If so this is easy, if not, more troublesome plumbing.

  13. #13
    Forum Contributor
    Join Date
    12-13-2012
    Location
    Italy
    MS-Off Ver
    Excel 2010
    Posts
    162
    Good evening,

    Find bellow one image with written coments (i dont know how te explain)

    Attachment 215162

    I have six folder full of excel files and I want to merge one file from each folder (so six files)...and to select each file from individual folder to use for merging I want that excel displays for each folder list of all files in it so I can select the right one.

    and the image

    MERGE SELECTED FILES .jpg
    Last edited by JBeaucaire; 02-21-2013 at 02:42 PM.

  14. #14
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Combine different tables in one table from selected files

    This is what I've come up with so far. Put the path to the main folder where your sub folders are found in Template cell B3, then this macro will pop open to the main folder each over and over and let you select a folder and a file and copy it into your wb, it will keep popping until you click CANCEL.

    Please Login or Register  to view this content.

  15. #15
    Forum Contributor
    Join Date
    12-13-2012
    Location
    Italy
    MS-Off Ver
    Excel 2010
    Posts
    162

    Re: Combine different tables in one table from selected files

    Ok, we are on the way to the end of my problem

    These macro opens the window to select the file..
    Is possible to combine these macro with that earlier that automatically opens the workbook based on value A3 that if the file with the name in B3 is not found it opens the window (in the preselected folder) to manually select the file?

  16. #16
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Combine different tables in one table from selected files

    Not sure exactly how to do that since you've indicated many folders as possible sources.

  17. #17
    Forum Contributor
    Join Date
    12-13-2012
    Location
    Italy
    MS-Off Ver
    Excel 2010
    Posts
    162

    Re: Combine different tables in one table from selected files

    The only was is to get the list of all files in the folder and list in a msg box to select which to open.

  18. #18
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Combine different tables in one table from selected files

    I don't understand what you're saying. The macro given will let you select files to open until you quit.

+ 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