+ Reply to Thread
Results 1 to 5 of 5

Cycle through all excel files in folder, compare and copy rows based on list

  1. #1
    Registered User
    Join Date
    05-27-2011
    Location
    Virginia
    MS-Off Ver
    Excel 365
    Posts
    86

    Cycle through all excel files in folder, compare and copy rows based on list

    Thank you experts in advance for your expertise and assistance. I need a macro that can cycle through all excel files in a specified directory. Once opened look on worksheet “Current RPM” in column A starting row 2 and compare it to worksheet “ListofSheets” column A of the active workbook. On the worksheet "ListOfSheets" in the active workbook, it will vary between 25 to 40 items. There will be between 3,000 to 4,000 rows from columns A to CB for each opened excel file in the specified directory. There will only be one unique ID listed in column A on each respective worksheet and no duplicates. There will be several rows (somewhere between 25 and 40) copied from each opened file. Once found, the rows are to be copied from each opened workbook to a new sheet named “Current Projects” in the active workbook pasting the data to column B because I’d like the filenames to be listed in column A. The data will have to be appended as each new set of rows will be added as you go until all files have been opened and applicable rows copied and the files closed. The number of files in the specified directory may be variable. Thanks again for any assistance that you are able to provide.

  2. #2
    Valued Forum Contributor saravnepali's Avatar
    Join Date
    01-14-2019
    Location
    Sydney Australia
    MS-Off Ver
    2010
    Posts
    447

    Re: Cycle through all excel files in folder, compare and copy rows based on list

    Can you attach sample workbook with expected result.
    If you think someone helped you, click on the "* Add Reputation" as a way to say thank you.

    If your problem is solved, go to Thread Tools and select Mark This Thread Solved

  3. #3
    Registered User
    Join Date
    05-27-2011
    Location
    Virginia
    MS-Off Ver
    Excel 365
    Posts
    86

    Re: Cycle through all excel files in folder, compare and copy rows based on list

    I've attached the Sample Data. Thanks for your reply. The final results are on the Current Projects worksheet.
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this !


    This starter demonstration must be pasted to the Current Projects worksheet module :

    PHP Code: 
    Sub Demo1()
        Const 
    ".xlsx"
          
    Dim F$, P$, R&, W$, L&
              
    "=ISNUMBER(MATCH(A2," &[ListOfSheets!A1].CurrentRegion.Address(External:=True) & ",0))"
              
    ThisWorkbook.Path Application.PathSeparator
              Me
    .UsedRange.Offset(1).Clear
              R 
    2
              W 
    Dir("*" E)
        While 
    ""
            
    With GetObject(W).Sheets("Current RPM").[A1].CurrentRegion
               
    .Range("CD2").Formula F
               
    .AdvancedFilter xlFilterInPlace, .Range("CD1:CD2")
               
    Application.Subtotal(103, .Columns(1)) - 1
            
    If L Then
               
    .Offset(1).Copy Cells(R2)
                
    Cells(R1).Resize(L).Value2 Replace(WE"")
                
    L
            End 
    If
               .
    Parent.Parent.Close False
            End With
              W 
    Dir
        Wend
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  5. #5
    Registered User
    Join Date
    05-27-2011
    Location
    Virginia
    MS-Off Ver
    Excel 365
    Posts
    86

    Re: Cycle through all excel files in folder, compare and copy rows based on list

    Thanks a million Marc, I'm able to use the code that you provided and it works perfectly!!!

+ 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. Replies: 4
    Last Post: 09-30-2019, 03:47 PM
  2. Copy Files from One Folder to Another Folder based on a List In Excel
    By civram1982 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-21-2019, 06:34 AM
  3. Replies: 18
    Last Post: 11-27-2018, 05:25 AM
  4. Copy Excel Files from a list into a new Folder
    By kalyan46 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-19-2018, 02:09 PM
  5. [SOLVED] open list of all .csv files in a folder and copy few colums in a excel of same sheet.
    By gnrao80 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-04-2014, 01:19 AM
  6. copy particular files to folder according to excel list
    By daxazz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-28-2012, 04:33 AM
  7. Macro to choose folder and cycle through all files
    By Mr.Pinches in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-08-2011, 04:04 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