+ Reply to Thread
Results 1 to 26 of 26

want to append all data of different excels of a folder into one excel sheet

  1. #1
    Forum Contributor
    Join Date
    03-11-2013
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    726

    want to append all data of different excels of a folder into one excel sheet

    I have different excel files those contains data in their sheet 1 only

    want to append data of all file into a single sheet

    attaching a code which i tried but getting error range not classified

    if a make the folder hidden at the said location it gives blank result
    Attached Images Attached Images

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

    Re: want to append all data of different excels of a folder into one excel sheet

    Option 1: Upgrade your Office from 2007 to any latest version to use Power Query to append data from multiple workbooks.

    Option 2: Attach a sample of your Main book and 1 sample of your books you want to get data from.
    Teach me Excel VBA

  3. #3
    Forum Contributor
    Join Date
    03-11-2013
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    726

    Re: want to append all data of different excels of a folder into one excel sheet

    sir

    i cant upgrade that is why i wanted to do it through VBA/code

    attaching samples

    these are just samples ,

    number f rows and columns are more in actual files

    Kindly append only those rows where column c is not blank

    in actual file i want where column I not blank ,that i will replace
    Attached Files Attached Files
    Last edited by ROHAN999; 08-30-2018 at 07:10 AM.

  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: want to append all data of different excels of a folder into one excel sheet

    Option 2: Attach a sample of your Main book and 1 sample of your books you want to get data from.

    main book should include desired results extracted from other book.

  5. #5
    Forum Contributor
    Join Date
    03-11-2013
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    726

    Re: want to append all data of different excels of a folder into one excel sheet

    sir i have attached sample and result file too, Kindly assist

  6. #6
    Forum Contributor
    Join Date
    03-11-2013
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    726

    Re: want to append all data of different excels of a folder into one excel sheet

    HTML Code: 
    this code appends the data but in my every excel file first row is a header and in every workbook its same.
    and i want to copy those rows only where column I is not blank.
    Last edited by ROHAN999; 08-30-2018 at 03:45 PM.

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

    Re: want to append all data of different excels of a folder into one excel sheet

    Try this

    PHP Code: 
    Sub AppendFiles()
    Application.ScreenUpdating False 'Stop screen flickering
    Static LoopEnd As Long '
    Last row of data in source file
    Dim j 
    As LongAs Long
    Dim strPath 
    As String    'Path to source file

    strPath = ThisWorkbook.Path '
    Get path to source file
    Set ObjShell 
    CreateObject("Shell.Application")
    Set objfolder ObjShell.Namespace(CStr(strPath))

    For 
    Each strfilename In objfolder.Items 'Loop through source files
        If Not strfilename = ThisWorkbook.Name Then
            With Sheet1
                .Range("Z1").Formula = "=CountA('" & ThisWorkbook.Path & "
    \[" & strfilename & "]Sheet1'!A:A" & ")"
                LoopEnd = .Range("Z1").Value - 1
                Destrow = .Range("A" & Rows.Count).End(xlUp).Row
                k = 2
                For j = Destrow To Destrow + LoopEnd
                    j = .Range("A" & Rows.Count).End(xlUp).Row + 1
                    '
    Fetch data from source file
                    
    .Range("A" j).Formula "='" ThisWorkbook.Path "\[" strfilename "]Sheet1'!$A$" k
                    
    .Range("B" j).Formula "='" ThisWorkbook.Path "\[" strfilename "]Sheet1'!$B$" k
                    
    .Range("C" j).Formula "='" ThisWorkbook.Path "\[" strfilename "]Sheet1'!$C$" k
                    k 
    1
                Next j
            End With
        End 
    If
    Next strfilename

    Sheet1
    .Columns("A:C").Value Sheet1.Columns("A:C").Value
    Set objfolder 
    Nothing
    Application
    .ScreenUpdating True
    End Sub 

    This code assumes the results and all source books are in a separate folder that does not contain any other irrelevant files
    Attached Files Attached Files
    Last edited by ImranBhatti; 08-30-2018 at 04:21 PM.

  8. #8
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: want to append all data of different excels of a folder into one excel sheet

    Try this code
    Put your files into a folder named "Files" .. except the main workbook
    Please Login or Register  to view this content.
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  9. #9
    Forum Contributor
    Join Date
    03-11-2013
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    726

    Re: want to append all data of different excels of a folder into one excel sheet

    error msg comes

    script out of range "Set ws = mWB.Worksheets("Sheet1")"

    as in all excel files sheet1 is not named as Sheet1

    in all file sheet 1 is named with different numbers
    like
    5000
    5007


    likewise sheet1 in all workbooks are named with different numbers
    Last edited by ROHAN999; 08-31-2018 at 12:59 AM.

  10. #10
    Forum Contributor
    Join Date
    03-11-2013
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    726

    Re: want to append all data of different excels of a folder into one excel sheet

    error msg comes

    script out of range "Set ws = mWB.Worksheets("Sheet1")"

    as in all excel files sheet1 is not named as Sheet1

    in all file sheet 1 is named with different numbers
    like
    5000
    5007


    likewise sheet1 in all workbooks are named with different numbers

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,518

    Re: want to append all data of different excels of a folder into one excel sheet

    Assuming all the files are in the same folder incl. result workbook.
    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    03-11-2013
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    726

    Re: want to append all data of different excels of a folder into one excel sheet

    here also same issue in

    rs.Open "Select * From `Sheet1$` In '" & myDir & "\" & fn & "' 'Excel 12.0;'", cn

    Sheet1$ is not a valid name-error

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,518

    Re: want to append all data of different excels of a folder into one excel sheet

    Quote Originally Posted by ROHAN999 View Post
    like
    5000
    5007


    likewise sheet1 in all workbooks are named with different numbers
    Missed above so forget about my code.

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,518

    Re: want to append all data of different excels of a folder into one excel sheet

    Please Login or Register  to view this content.

  15. #15
    Forum Contributor
    Join Date
    03-11-2013
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    726

    Re: want to append all data of different excels of a folder into one excel sheet

    Set LastR = ws.Range("a" & Rows.Count).End(xlUp)(2)

    here run time error 1004 is coming

    application-object defined error

  16. #16
    Forum Contributor
    Join Date
    03-11-2013
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    726

    Re: want to append all data of different excels of a folder into one excel sheet

    code opens first file to copy then this error comes

  17. #17
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,518

    Re: want to append all data of different excels of a folder into one excel sheet

    Your Excel must be something wrong.
    Attached Files Attached Files

  18. #18
    Forum Contributor
    Join Date
    03-11-2013
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    726

    Re: want to append all data of different excels of a folder into one excel sheet

    Yes its serving the purpose but can it copy only those rows where column i is not blank

  19. #19
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,518

    Re: want to append all data of different excels of a folder into one excel sheet

    Is there good reason for us to help you more without any word of appreciation?

    Ask you friend and I'm not.

  20. #20
    Forum Contributor
    Join Date
    03-11-2013
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    726

    Re: want to append all data of different excels of a folder into one excel sheet

    No sir its not like that

    i am almost there and when i am corresponding to you only that means it really serving my purpose too, even before replying this i have rated you

    kindly assist to modify it further

  21. #21
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,518

    Re: want to append all data of different excels of a folder into one excel sheet

    That's after my last post, anyway.

    If you are substituting saying "thanks" to the rep, I hope you gave the reps to all the posters who tried to help you in this thread.

    Upload the workbooks with before/after.
    Your uploaded workbooks have data only up to col.C.

  22. #22
    Forum Contributor
    Join Date
    03-11-2013
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    726

    Re: want to append all data of different excels of a folder into one excel sheet

    Attached sir
    Attached Files Attached Files

  23. #23
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,518

    Re: want to append all data of different excels of a folder into one excel sheet

    Change to
    Please Login or Register  to view this content.

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

    Re: want to append all data of different excels of a folder into one excel sheet

    @ sir jindon

    I did not try to adjust it into your code but I think the bellow code can get the name of the sheet for code in post#11. It returns an array of worksheet names of the closed book (tested).(sample book attached as download from the web)
    Please Login or Register  to view this content.

    PHP Code: 
    Option Explicit

    Public Sub DemoGetSheetNames()

        
    Dim lNumEntries As Long
        Dim szFullName 
    As String
        Dim szFileSpec 
    As String
        Dim aszSheetList
    () As String
        
        Sheet1
    .UsedRange.Clear

        szFileSpec 
    "Excel Files (*.xl*),*.xl*"
        
        
    szFullName CStr(Application.GetOpenFilename(szFileSpec, , "Select an Excel File"))
        
        
    ''' Continue if the user did not cancel the dialog.
        If szFullName <> CStr(False) Then
            GetSheetNames szFullName, aszSheetList()
            lNumEntries = UBound(aszSheetList) - LBound(aszSheetList) + 1
            Sheet1.Range("A1").Resize(lNumEntries).Value = Application.WorksheetFunction.Transpose(aszSheetList())
            Sheet1.Range("A1").EntireColumn.AutoFit
        End If

    End Sub


    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''' 
    Comments:   Returns a string array containing the list of worksheets in
    '''             the specified workbook.
    '''             
    NOTERequires references to the following object library:
    '''             * Microsoft ActiveX Data Objects 2.5 Library (or higher version)
    '''
    ''' Arguments:  szFullName      [in] The full path and filename of the workbook
    '''                             
    whose worksheet list you want to query.
    '''             aszSheetList()  [out] Will be loaded with a list of worksheets
    '''                             
    in the workbook specified by szFullName.
    '''
    ''' 
    Date        Developer       Action
    ''' --------------------------------------------------------------------------
    ''' 
    05/13/05    Rob Bovey       Created
    '''
    Private Sub GetSheetNames(ByRef szFullName As String, ByRef aszSheetList() As String)

        Dim bIsWorksheet As Boolean
        Dim objConnection As ADODB.Connection
        Dim rsData As ADODB.Recordset
        Dim lIndex As Long
        Dim szConnect As String
        Dim szSheetName As String

        Erase aszSheetList()
        If Application.Version < 12 Then
            szConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & szFullName & ";Extended Properties=Excel 8.0;"
        Else
            szConnect = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & szFullName & ";Extended Properties=Excel 8.0;"
        End If

        Set objConnection = New ADODB.Connection
        objConnection.Open szConnect
        Set rsData = objConnection.OpenSchema(adSchemaTables)

        Do While Not rsData.EOF
            bIsWorksheet = False
            szSheetName = rsData.Fields("TABLE_NAME").Value
            If Right$(szSheetName, 1) = "$" Then
                ''' 
    This is a simple sheet nameRemove the trailing "$" and continue.
                
    szSheetName Left$(szSheetNameLen(szSheetName) - 1)
                
    bIsWorksheet True
            
    ElseIf Right$(szSheetName2) = "$'" Then
                
    ''' This is a sheet name with spaces and/or special characters.
                ''' 
    Remove the right "&'" characters.
                
    szSheetName Left$(szSheetNameLen(szSheetName) - 2)
                
    ''' Remove the left single quote character.
                szSheetName = Right$(szSheetName, Len(szSheetName) - 1)
                bIsWorksheet = True
            End If
            If bIsWorksheet Then
                ''' 
    Embedded single quotes in the sheet name will be doubled up.
                
    ''' Replace any doubled single quotes with one single quote.
                szSheetName = Replace$(szSheetName, "''", "'")
                ''' Load the processed sheet name into the array.
                ReDim Preserve aszSheetList(0 To lIndex)
                aszSheetList(lIndex) = szSheetName
                lIndex = lIndex + 1
            End If
            rsData.MoveNext
        Loop

        rsData.Close
        Set rsData = Nothing
        objConnection.Close
        Set objConnection = Nothing

    End Sub 
    Attached Files Attached Files
    Last edited by ImranBhatti; 08-31-2018 at 05:53 AM.

  25. #25
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,518

    Re: want to append all data of different excels of a folder into one excel sheet

    I know how to extract sheet names from closed workbook via ADO, however it doesn't help in this case.

    It is not sorted in sheet index, but sorted by the sheet names.

  26. #26
    Forum Contributor
    Join Date
    03-11-2013
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    726

    Re: want to append all data of different excels of a folder into one excel sheet

    thanx alot

+ 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. How to get data from many excels in one folder
    By asd1234asd in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-28-2016, 04:08 AM
  2. VBA code to password protect all excels files in a folder
    By jaincool123 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-03-2014, 07:19 AM
  3. [SOLVED] Loop to open all workbooks in folder and append data to single sheet
    By beng404 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-04-2013, 01:45 PM
  4. Replies: 1
    Last Post: 07-17-2012, 11:05 PM
  5. Replies: 0
    Last Post: 12-07-2010, 12:41 PM
  6. Email data from Excel Form and append it to another sheet.
    By Prometheus_au in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-23-2009, 11:40 PM
  7. [SOLVED] Append the data given in diff sheets of an Excel File to one sheet
    By sansk_23 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-09-2005, 09:06 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