+ Reply to Thread
Results 1 to 4 of 4

Need a VBA to combine two excel files

  1. #1
    Registered User
    Join Date
    07-12-2016
    Location
    Livermore
    MS-Off Ver
    2013
    Posts
    2

    Need a VBA to combine two excel files

    I'm new to VBA so I was hoping someone could help me with my problem. GIVEN:

    First excel file has X number of columns with Y rows

    A B C D E (columns)
    1 2 3 4 5 (row1)
    6 7 8 9 10 (row2)

    and 2nd excel has

    A B C D (columns)
    1 2 3 4 (row1)
    6 7 8 9 (row2)
    a b c d (row 3)
    e f g h (row4)

    trying to combine so it becomes
    A B C D E (columns)
    1 2 3 4 5 (row1)
    6 7 8 9 10 (row2)
    a b c d (row 3)
    e f g h (row4)

    need it to loop combine for over 20 columns and 500 rows

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,008

    Re: Need a VBA to combine two excel files

    You don't need to loop. You could paste the second sheet's data block below the first sheet's, so that you have:

    A B C D E (columns)
    1 2 3 4 5 (row1)
    6 7 8 9 10 (row2)
    1 2 3 4 (row3)
    6 7 8 9 (row4)
    a b c d (row5)
    e f g h (row6)

    then select the first four columns (based on your example)and use Data / Remove Duplicates , and you will get:

    A B C D E (columns)
    1 2 3 4 5 (row1)
    6 7 8 9 10 (row2)
    a b c d (row3)
    e f g h (row4)
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    07-12-2016
    Location
    Livermore
    MS-Off Ver
    2013
    Posts
    2

    Re: Need a VBA to combine two excel files

    Hi, Thanks for the fast response, I was wondering what if I had it like this:

    A B C D E (columns)
    1 2 X X 5 (row1)
    6 7 8 9 10 (row2)
    1 2 3 4 (row3)
    6 7 8 9 (row4)
    a b c d (row5)
    e f g h (row6)

    And I wanted to merge while Keeping the "X X" changed values the same. I tried to use the duplicate and only highlight the other columns but I noticed that everything shifted up.

    A B C D E (columns)
    1 2 X X 5 (row1)
    6 7 8 9 10 (row2)
    a b c d (row3)
    e f g h (row4)

    Thanks!

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,008

    Re: Need a VBA to combine two excel files

    Sorry, my instructions weren't clear.

    Use Data / Remove Duplicates (on the entire data set), but only select the columns that indicate duplicates - for your first example, that was A, B, C, and D. For your second example, that would be A and B.

+ 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. Need VBA: Combine excel files to 1 sheet
    By navafolk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-05-2016, 10:06 AM
  2. Combine two excel files into one
    By Shahip Raja in forum Excel General
    Replies: 5
    Last Post: 11-19-2015, 10:37 AM
  3. Excel vba to tel adobe combine two pdf files based on a spcified list of files
    By Abbadon486 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-30-2014, 12:04 PM
  4. Combine multiple excel files to one
    By anoopbaiju in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 03-03-2013, 09:04 AM
  5. Macro to combine several excel files
    By prazumov in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-16-2013, 02:21 AM
  6. How to combine two excel files?
    By dreamgirl in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-06-2006, 05:07 PM
  7. [SOLVED] how to combine multiple files in ms excel
    By fifi in forum Excel General
    Replies: 1
    Last Post: 01-12-2005, 08:06 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