+ Reply to Thread
Results 1 to 2 of 2

Excel files merging in wrong order

Hybrid View

  1. #1
    Registered User
    Join Date
    04-12-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    1

    Excel files merging in wrong order

    I am just starting with VBA so I don't know much. I am using the code below to combine excel files into one. The files are labeled as "wk of 1-02-2012", wk of "1-09-2017" etc for 52 weeks. My problem is the sheets are in descending order and I need them starting in Jan not Dec. Can anyone help with this? Thank you!

    Sub ConslidateWorkbooks()
    Dim FolderPath As String
    Dim Filename As String
    Dim Sheet As Worksheet
    Application.ScreenUpdating = False
    FolderPath = Environ("userprofile") & "\Desktop\Test\"
    Filename = Dir(FolderPath & "*.xls*")
    Do While Filename <> ""
    Workbooks.Open Filename:=FolderPath & Filename, ReadOnly:=True
    For Each Sheet In ActiveWorkbook.Sheets
    Sheet.Copy After:=ThisWorkbook.Sheets(1)
    Next Sheet
    Workbooks(Filename).Close
    Filename = Dir()
    Loop
    Application.ScreenUpdating = True
    End Sub

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Excel files merging in wrong order

    Two things - use code tags:
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

    and change this
    Sheet.Copy After:=ThisWorkbook.Sheets(1)
    to this
    Sheet.Copy After:=ThisWorkbook.Sheets(Sheets.Count)
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

+ 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. Mail Merging Dates Excel to Word Month and day wrong way.
    By gonzalraf in forum Excel General
    Replies: 18
    Last Post: 12-10-2013, 04:47 PM
  2. Replies: 1
    Last Post: 11-03-2013, 06:18 PM
  3. Excel alphabetical order is wrong
    By HelpExc in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-26-2012, 04:37 PM
  4. Merging Excel Files
    By Xaivor in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-17-2008, 09:53 PM
  5. Merging two Excel files
    By milindsaraswala in forum Excel General
    Replies: 0
    Last Post: 11-13-2007, 11:18 PM
  6. Merging Different excel files into one
    By Neill in forum Excel General
    Replies: 0
    Last Post: 10-27-2005, 05:05 PM
  7. [SOLVED] merging my excel files
    By Donna YaWanna in forum Excel General
    Replies: 1
    Last Post: 06-13-2005, 08:05 PM
  8. Replies: 1
    Last Post: 06-08-2005, 11:05 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