Results 1 to 12 of 12

Modify the code to consolidate files in same order as saved in source folder

Threaded View

  1. #1
    Forum Contributor
    Join Date
    12-11-2014
    Location
    dubai
    MS-Off Ver
    2010
    Posts
    142

    Modify the code to consolidate files in same order as saved in source folder

    Hi Guys
    I have this code which consolidates the files from fpath into master file.
    i have 20 files in fpath and i have numbered it from 1 to 20.
    Everytime i run the macro it picks the file in radom order and consilidates it, how to modify it pick in the same order as its being put in the fpath.
    Dim wbData As Workbook, wbMain As Workbook, wsMain As Worksheet, wsData As Worksheet
    Dim LR As Long, NR As Long, fPath As String, fName As String
    
    Set wbMain = ThisWorkbook
                                        
    fPath = "Z:\Demand & Supply\Demand & Supply\3.Color Breakdown 2.0\Sep_Oct'15 Production - Testing\3.Master\"
    fName = Dir(fPath & "*.xlsm")
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    On Error Resume Next
    
    Do While Len(fName) > 0
        If fName <> ThisWorkbook.Name Then
            Set wbData = Workbooks.Open(fPath & fName)
            For Each wsData In wbData.Worksheets
                Set wsMain = wbMain.Sheets(wsData.Name)
                If Not wsMain Is Nothing Then
                    NR = wsMain.Range("A" & Rows.Count).End(xlUp).Row + 1
                    With wsData
                        LR = .Range("A" & .Rows.Count).End(xlUp).Row
                        .Range("A4:A" & LR).EntireRow.Copy wsMain.Range("A" & NR)
                    End With
                    Set wsMain = Nothing
                End If
            Next wsData
            
            wbData.Close False
        End If
        
        fName = Dir
    Loop
    Thanks for any assistance
    Last edited by 6StringJazzer; 08-07-2015 at 10:49 AM. Reason: Moved from Excel General

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Copy certain files from Source folder to Destination folder
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-16-2015, 08:56 PM
  2. [SOLVED] How can I modify this code so that I can only consolidate certain columns?
    By alchavar in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-10-2015, 01:10 PM
  3. [SOLVED] How to modify the macro wich summarize all the files from the particular folder?
    By Arty_1 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 02-17-2015, 08:35 PM
  4. Macro to export excel files from outlook folder and consolidate
    By xxxnac in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-25-2014, 02:18 PM
  5. How to Send automated mails with attachment files saved in a folder?
    By yemnirmal in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-20-2014, 03:16 PM
  6. copying data from excel files in a source folder to target folder
    By Javed07 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-22-2013, 04:27 PM
  7. modify ALL files in a folder
    By TedH in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-13-2009, 04:53 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