+ Reply to Thread
Results 1 to 3 of 3

Macro that merges several excel files into one

  1. #1
    Registered User
    Join Date
    04-08-2016
    Location
    Here
    MS-Off Ver
    Excel 2007
    Posts
    2

    Macro that merges several excel files into one

    Hello!
    I tried to come up with a solution that can make my job easier but for some reason it's not very consistent. I will mention that I am quite new to the world of VBA and Excel but I'm trying to learn a few tricks, so bare with me please.

    This is my problem: I have to add several separate excel files in one spreadsheet so that I can make a report on that data. Because sometimes there are quite a lot of files I tried to figure out a way to add them automatically. Every file basically looks like this:
    for excel forum.jpg
    The files are saved daily and the usually have a filter active so I figured out a macro that does the following:
    -first I have to get all the files I want to add into one folder
    -then I open up a new spreadsheet, open VBA and paste my macro in and run it
    -then the macro opens every excel file,clears the filters,selects every row of data except the first row,copies them in the new spreadsheet and closes the excel files without saving any changes.
    -after it's done I insert the first row into my new spreadsheet and start working on the report.

    So this saves up quite a lot of time but sometimes it doesn't work, it just adds the first row (the one with the First Name, Last Name, etc) from every excel file and no other row of data, and I don't really understand why.
    Anyway, maybe someone can take a look at this macro and point out what's wrong, or even tell me if there is an easier way to do this.
    This is the macro I came up with just by adding bits and pieces from the internet, so don't laugh pls.
    Please Login or Register  to view this content.
    Thank you for your time and patience, and hopefully for your help.

    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
    Last edited by 6StringJazzer; 04-08-2016 at 10:23 AM.

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Macro that merges several excel files into one

    The logic appears to be OK. Do your sheets contain more that 65536 rows or gaps in column A?
    Martin

  3. #3
    Registered User
    Join Date
    04-08-2016
    Location
    Here
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Macro that merges several excel files into one

    No, not even close to 65636. There usually are close to a thousand. From what I can figure out there must be something wrong with the formatting of the excel files when the macro doesn't work properly. Or maybe with this part of the code, since it does exaclty the opposite, instead of deleting the first row, it deletes everything else.
    Please Login or Register  to view this content.
    Later edit:
    Ok, so I messed with it a bit and I think I found out why it isn't consistent all the time.
    Some of my databases have no info in column A, there's just the name of the column in A1 and blank from A2 downwards. After I inserted some random data in column A the macro worked just fine.
    Does anyone have an ideea how to fix this in the code? I'm not sure how to write an "if" command like "if rows are blank then copy them anyway" :D

    Thanks anyway!
    Last edited by Rob Swift; 04-11-2016 at 06:17 AM.

+ 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. [SOLVED] Excel Macro that merges duplicates and adds two calculations
    By jodo2 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-28-2016, 03:49 PM
  2. VB that merges multiple files into one worksheet - but does this 3 times - see detail
    By BlueberryTech in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-06-2015, 10:01 AM
  3. Excel Checkboxes Performing Word Document Merges
    By sammyp1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-28-2014, 03:09 PM
  4. [SOLVED] Macro that merges duplicate rows based on unique values - Need to edit current code
    By niya429 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-27-2014, 02:57 PM
  5. [SOLVED] Macro that merges matching data from two sheets and pastes to a new sheet (in line)
    By njmiller31 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-16-2013, 11:06 AM
  6. create macro that merges cells and then transposes them into other worksheet
    By jloyzaga in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-17-2011, 07:36 PM
  7. Form button controlled macro that merges data from rows into Word & saves them
    By a.mack123 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-18-2010, 07:42 PM

Tags for this Thread

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