+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Registered User
    Join Date
    03-09-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    10

    How to create one file from many excel files

    Hello my first post,

    First of all great place, I plan to spend a lot of time here, because I'm new to excel and I need to know many things.

    I will be very thankful for help ...

    Here is what I need.I have several excel files, and I want to create one from them.First option is copy past but that is time consuming, so is there any other way.

    So lets say that is my first file:

    A B
    a1 b1
    a2 b2


    And let's say that is my second file

    A B
    a3 b3
    s f
    v h

    So I want to create this one

    A B
    a1 b1
    a2 b2
    a3 b3
    s f
    v h

    Is there a way, please?I have many excel files that are in one directory.
    Last edited by bodmov; 03-13-2010 at 04:40 AM.

  2. #2
    Forum Guru rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: How to create one file from many excel files

    BodMov,

    Welcome to the forum. As you are an inexperienced excel user I would do the following.

    Have all files open including the consolidation file.
    When you right click a tab (bottum) you can copy/move it to the consolidation file.
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  3. #3
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,228

    Re: How to create one file from many excel files

    Hi BodMov, this will be a VBA question, in case you didn't realize. I have a stock macro to import all the files in a folder into a single stacked worksheet. Here's the code:
    Code:
    Sub Consolidate()
    'Author:     JBeaucaire'
    'Date:       9/15/2009     (2007 compatible)'
    'Summary:    Open all Excel files in a specific folder and merge data'
    '            into one master sheet (stacked)'
    '            Moves imported files into another folder'
    Dim fName As String, fPath As String, fPathDone As String, OldDir As String
    Dim LR As Long, NR As Long
    Dim wbkOld As Workbook, wbkNew As Workbook, ws As Worksheet
    
    'Setup'
        Application.ScreenUpdating = False
        Application.EnableEvents = False
        Application.DisplayAlerts = False
        
        Set wbkNew = ThisWorkbook
        wbkNew.Activate
        Sheets("Master").Activate   'sheet report is built into'
        
        If MsgBox("Import new data to this report?", vbYesNo) = vbNo Then Exit Sub
        
        If MsgBox("Clear the old data first?", vbYesNo) = vbYes Then
            Cells.Clear
            NR = 1
        Else
            NR = Range("A" & Rows.Count).End(xlUp).Row + 1
        End If
    
    'Path and filename'
        OldDir = CurDir             'memorizes the current working path'
        fPath = "C:\2010\"
        fPathDone = "C:\2010\Imported\"
        ChDir fPath
        fName = Dir("*.xl*")      'filtering key, change to suit'
    
    'Import a sheet from found file'
        Do While Len(fName) > 0
            'Open file'
                Set wbkOld = Workbooks.Open(fName)
            'Find last row and copy data'
                LR = Range("A" & Rows.Count).End(xlUp).Row
                Range("A1:A" & LR).EntireRow.Copy _
                    wbkNew.Sheets("Master").Range("A" & NR)
            'close file'
                wbkOld.Close False
            'Next row'
                NR = Range("A" & Rows.Count).End(xlUp).Row + 1
            'move file to IMPORTED folder'
                Name fPath & fName As fPathDone & fName
            'ready next filename'
                fName = Dir
        Loop
    
    'Cleanup'
        ActiveSheet.Columns.AutoFit
        Application.DisplayAlerts = True
        Application.EnableEvents = True
        Application.ScreenUpdating = True
    
    'restores original working path'
        ChDir OldDir
    End Sub
    ========
    SETUP:

    1) Edit the code above so the fPath is where your files to import exists.
    2) On your computer, create another folder inside that path call Imported, and then make sure that path is listed in the code for the fPathDone variable.
    3) Put the macro into your report workbook:

    How/Where to install the macro:

    A. Open up your report workbook
    B. Get into VB Editor (Press Alt+F11)
    C. Insert a new module (Insert > Module)
    D. Copy and Paste in your code (given above)
    E. Get out of VBA (Press Alt+Q)
    F. Save your sheet in a different directory from the import files, or save it into the ...\IMPORTED folder.

    The macro is installed and ready to use.

    =======
    USAGE:
    Press Alt-F8 and select Consolidate from the macro list.
    Last edited by JBeaucaire; 03-09-2010 at 04:34 AM.
    _________________
    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!)

  4. #4
    Registered User
    Join Date
    03-09-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: How to create one file from many excel files

    thanks rwgrietveld

    actually you mean to copy paste the files one by one, or ...

    yes that is possible but I have a lot of information and it will takes me a lot of time.i have to copy/paste more than 100 files every day...

    so is there easier option for me , please

  5. #5
    Forum Guru rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: How to create one file from many excel files

    BodMov,

    I didn't want to direct you to VBA just yet, but like JB states: inescapable VBA

    Use JB's solution. That's the best approach when dealing with >100 files per day.
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  6. #6
    Registered User
    Join Date
    03-09-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: How to create one file from many excel files

    JBeaucaire Thank you really much.

    I followed your steps, but I get this error:

    Run-time error '9'

    Subscript out of range



    In debug mode:

    Sheets("Master").Activate 'sheet report is built into'

    this is highlited with yellow
    What to do???

  7. #7
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,228

    Re: How to create one file from many excel files

    Either create a sheet in you workbook called Master

    or

    Change that line of code and put in the sheetname you want used.
    _________________
    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!)

  8. #8
    Registered User
    Join Date
    03-09-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: How to create one file from many excel files

    Thanks again but it does not works,

    I got this messages when I run the macro:
    Import new data to this report? Yes No
    Clear the old data first?Yes Not

    I clicked yes yes but nothing appears.What else can I do.I think I almost do it ...

  9. #9
    Registered User
    Join Date
    03-09-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: How to create one file from many excel files

    The next error that I see in debud is :

    Name fPath & fName As fPathDone & fName

    actually where do I have to see my new excel document?
    Last edited by bodmov; 03-09-2010 at 06:59 AM.

  10. #10
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,228

    Re: How to create one file from many excel files

    VBA is a tough nut to crack for the first time. Let's start over.

    Tell me:

    1) The name of the SHEET in your workbook you want to compile this report into. In my macro it's called Master...

    2) The complete path to the folder where your 100s of files will be

    3) How many sheets are in those 100s of files? Can we simply import the active sheet when each one opens?

    If not, what is the sheet name you want imported from those files?

    4) Do the import sheets have titles in row1? Do those need to be skipped or can we just import it all?

    5) Have you created another folder called IMPORT inside the path that holds the files?

    NOTE: When you run this macro from inside the Report workbook, that workbook needs to running from a different path than your import files. I've seen in the past where people put the report into the same folder...it imports all the files and then gets to the report file itself and reopens it...effectively erasing the work already done. Oops.
    _________________
    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!)

  11. #11
    Registered User
    Join Date
    03-09-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: How to create one file from many excel files

    Thank you so much for your help.

    As i mentioned before I'm new to excel.I've been using excel for several days...

    Here is what I did?
    C:\Documents and Settings\Administrator\My Documents\1\3
    C:\Documents and Settings\Administrator\My Documents\1\3\Imported
    Actually where do I have to put all of my files, and where will appear the result?Will I have to create any excel where I expect the result or it will just be created?Is so what name?

    I saved the macro in different directory

    "1) The name of the SHEET in your workbook you want to compile this report into. In my macro it's called Master..."
    Sheet1
    , but I'm not sure I know what exactly is report workbook

    3) How many sheets are in those 100s of files? Can we simply import the active sheet when each one opens?
    Actually I have many excel files with only one sheet of data.

    4) Do the import sheets have titles in row1? Do those need to be skipped or can we just import it all?
    no everything should be imported

  12. #12
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,228

    Re: How to create one file from many excel files

    Here, just take this workbook and save it somewhere, open it and run the Consolidate macro.
    Attached Files Attached Files
    _________________
    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!)

  13. #13
    Registered User
    Join Date
    03-09-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: How to create one file from many excel files

    I don't want what to tell you

    IT REALLY WORKS

    THANK YOU !!!

  14. #14
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,228

    Re: How to create one file from many excel files

    Glad to hear it.

    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
    _________________
    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!)

  15. #15
    Registered User
    Join Date
    03-09-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: How to create one file from many excel files

    Hi of course I'll do that , but I have last question,

    Actually it worked but I'm trying to consolidate files from this site:
    https://adwords.google.com/select/KeywordToolExternal

    and I noticed that it works only with some types of files (I'm not sure)

    What I mean is when I create excel documents only with letters it works perfectly, but when I use excel files extracted from this site (they have also numbers), it does not works ...

    I'm not sure what is the problem.Is it works if there are numbers in it, or maybe the format can be the problem.

    Kindly go to that site enter any keywords, click you'll see:
    Download all keywords: text, .csv (for excel), .csv

    Download cvs, and tell me is that the same format and what can be the problem it does not work with such a files.

    Many thanks again ...

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.2.0