+ Reply to Thread
Results 1 to 10 of 10

Combine many .csv files into one excel sheet

  1. #1
    Registered User
    Join Date
    02-27-2018
    Location
    Kenya
    MS-Off Ver
    2016
    Posts
    14

    Combine many .csv files into one excel sheet

    Hello everyone
    Please can you help me:
    I have more than 100 files with tables (format .csv, find some of them attached) and I need to combine them into one excel sheet, putting them in many columns like in "All stations together.xlsx". I can copy and paste but I have so many other files like that and it will take me and eternity. Can someone help me with a code?
    Thank you
    PS: No need to repeat the first column of each .csv and the files names are not necessarily St0, St2, St3....they may change to other names.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor PeteABC123's Avatar
    Join Date
    09-21-2012
    Location
    Chicago, IL
    MS-Off Ver
    MS Office 365 ver 2202
    Posts
    1,104

    Re: Combine many .csv files into one excel sheet

    I did some hunting. If you have MS Access, here's a tool to import all your csv's in a single operation. https://superuser.com/questions/1131...iple-csv-files

    Once done, export into Excel.
    Pete

  3. #3
    Registered User
    Join Date
    02-27-2018
    Location
    Kenya
    MS-Off Ver
    2016
    Posts
    14

    Re: Combine many .csv files into one excel sheet

    PeteABC123, thank you. Is it a macro code that I have to run into Access? Please can you help me with the steps to run it into Access? Have Access 2016 but don't know how to create and run the macro.

  4. #4
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Combine many .csv files into one excel sheet

    Try this from All Stations book

    PHP Code: 
    Sub combineStations()
    Application.ScreenUpdating False
    Dim k 
    As Integer
    Dim strPath 
    As String
    Dim myCSV 
    As String
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    strPath ThisWorkbook.Path
    Set ObjShell 
    CreateObject("Shell.Application")
    Set objfolder ObjShell.Namespace(CStr(strPath))
    0
    For Each strfilename In objfolder.Items
        
    If strfilename Like "St*" Then
            On Error Resume Next
            Workbooks
    .Open strPath "\" & strfilename
                ActiveWindow.Visible = False
                myCSV = strfilename
                k = ThisWorkbook.Sheets(1).Cells(1, 10000).End(xlToLeft).Column + 1
                ThisWorkbook.Sheets(1).Columns(k).Value = Workbooks(myCSV).Sheets(1).Columns(1).Value
                ThisWorkbook.Sheets(1).Columns(k + 1).Value = Workbooks(myCSV).Sheets(1).Columns(2).Value
                Workbooks(myCSV).Close True
        End If
    Next strfilename
    Set objfolder = Nothing
    Application.ScreenUpdating = True
    End Sub 
    Teach me Excel VBA

  5. #5
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Combine many .csv files into one excel sheet

    Assuming all your files including the "All stations" are in the same directory.

  6. #6
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,913

    Re: Combine many .csv files into one excel sheet

    Just load via Get & Transform. From Folder menu.

    It will combine as append rather then merge. But you can use the "Removed Other Columns1" step to iterate over table and merge one another.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  7. #7
    Registered User
    Join Date
    02-27-2018
    Location
    Kenya
    MS-Off Ver
    2016
    Posts
    14

    Re: Combine many .csv files into one excel sheet

    ImranBhatti Thanks a lot this is working as I want
    Last edited by Wendso; 08-29-2018 at 10:03 PM.

  8. #8
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Combine many .csv files into one excel sheet

    If it helps you and fully answers your question , please do the following:

    1: Mark your thread as "Solved" (On top right of your first post in the current thread click on "Thread Tools>Mark as Solved"
    2: Give some rep to the post that helped you. (At bottom left side of the post that helped click on * button)

  9. #9
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Combine many .csv files into one excel sheet

    Thanks for the rep+

  10. #10
    Forum Contributor
    Join Date
    03-22-2017
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    230
    Did you ever go thourgh the get data to insert data from folder. It in the data tab. Not sure your excel version got or not. But it is an option to try with.

    Here the link for your reference.

    https://support.office.com/en-us/article/combine-files-in-a-folder-with-combine-binaries-power-query-94b8023c-2e66-4f6b-8c78-6a00041c90e4

+ 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. Combine the second sheet of a few files into one worksheet.
    By shir02 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-03-2017, 12:06 PM
  2. Combine Excel files into Single sheet (values only) add column for filename
    By supremesabre in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-18-2017, 11:48 AM
  3. Need VBA: Combine excel files to 1 sheet
    By navafolk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-05-2016, 10:06 AM
  4. VBA to combine the first sheet of numerous excel files into one master document
    By Peep_Show_Fan in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-29-2016, 11:37 AM
  5. Replies: 0
    Last Post: 10-12-2015, 10:02 AM
  6. Excel vba to tel adobe combine two pdf files based on a spcified list of files
    By Abbadon486 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-30-2014, 12:04 PM
  7. [SOLVED] Combine data of some cells in multiple excel files into one sheet
    By ricdamiani in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 08-07-2013, 12:07 AM

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