Results 1 to 2 of 2

Thread: Copy the data in multiple Excel WB to one sheet

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2009
    Posts
    1

    Copy the data in multiple Excel WB to one sheet

    Below is the code where I am trying to copy the data in multiple Excel workbook data in one folder to one excel sheet this code is working fine in MS 2003 but it is not at all working in ms 2007

    Can you please help me to debug this code to run in MS 2007



    HTML Code:
    Sub Gather()
    Application.ScreenUpdating = False
    Dim Master As Worksheet
        Dim strName As String
       strName = InputBox(Prompt:="Select Sheet To perfrom selected opeartion.", _
            Title:="Sheet NAME", Default:="Sheet1")
           Debug.Print (strName)
       Set Master = Worksheets(strName)
       Master.Rows.Delete
       Master.Columns.Delete
       'MsgBox "Point to the folder containing all the files in the next dialog - then click Cancel"
       'Application.GetOpenFilename
       On Error Resume Next
       With Application.FileSearch
           .NewSearch
           .LookIn = "C:\Excel Sheets"
           .FileType = msoFileTypeExcelWorkbooks
           .Execute
           'For i = 1 To .FoundFiles.Count
           For i = 1 To 19
               Workbooks.Open .FoundFiles(i), False, True
               Err.Clear
               Sheets("Sheet1").Activate
               If Err.Number <> 0 Then
                   ActiveWorkbook.Close False
                   GoTo NextWB
               End If
               l = Master.UsedRange.Rows.Count
               ActiveSheet.UsedRange.Copy
               Master.Cells(l + 1, 1).PasteSpecial
               Application.CutCopyMode = False
               'ActiveWorkbook.Close False
    NextWB:
           Next
       End With
       Range("A1").Select
       Application.ScreenUpdating = True
       MsgBox "Data is copied to selelcted sheet - " & strName, vbInformation
    End Sub
    Thanks for the help in Advance

    Regards
    Shrinivas
    Last edited by shrinivas4u; Dec 23rd, 2009 at 02:30 AM. Reason: Code Tag

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Copy the data in multiple Excel WB to one sheet

    but it is not at all working in ms 2007
    what happens?
    any error?

    i believe that application.filesearch is no longer available, so some other method would need to be used
    see if you can utilise
    Application.GetOpenFilename
    otherwise build your own list of files using DIR
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width