+ Reply to Thread
Results 1 to 1 of 1

Merge 2 sheets into 1 new workbook based on 1 column's matching values between the 2 sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    01-02-2013
    Location
    NY, United States
    MS-Off Ver
    Excel 2003
    Posts
    4

    Merge 2 sheets into 1 new workbook based on 1 column's matching values between the 2 sheet

    This code looks like it can do what I want with a little modification.

    Quote Originally Posted by Kiran.Sunkara View Post
    See if this works for you.
    Private Sub CommandButton1_Click()
    
    Dim lrow1 As Long, lrow2 As Long, Rng As Range
    
    lrow1 = Sheets("Master").Cells(Rows.Count, 4).End(xlUp).Row
    lrow2 = Sheets("Sheet6").Cells(Rows.Count, 4).End(xlUp).Row
    
    For i = 2 To lrow1
        If Sheets("Master").Range("D" & i) > 4000 Then
            Sheets("Sheet6").Range("A" & lrow2 + 1 & ":D" & lrow2 + 1).Value = Sheets("Master").Range("A" & i & ":D" & i).Value
            Sheets("Sheet6").Range("G" & lrow2 + 1).Value = Sheets("Master").Range("G" & i).Value
            Sheets("Sheet6").Range("M" & lrow2 + 1).Value = Sheets("Master").Range("M" & i).Value
            lrow2 = lrow2 + 1
        End If
    Next i
    Worksheets("Master").Activate
    MsgBox "Done!"
    End Sub

    I used the following formulas to pull unique values on sheet1 and place them on sheet2. This works fine but it is too slow to do this with 20+ columns.
    http://www.excelforum.com/excel-form...her-sheet.html

    However I couldn't use a macro to do that part because on sheet2 we have an extra 10+ columns that we enter manually. Basically a report comes from an automated system every week. We feed it into sheet1 and sheet2 extracts the unique cases based on an ID# column.

    I need a macro that will compare sheet1 which has duplicate rows with the same values, and sheet2 which has no duplicates because I used the above array formula to extract only unique rows. The array formula is too slow to copy all columns to sheet2. I need a macro to copy over the additional 20+ columns from sheet1 over to sheet2 and save as a new workbook. I basically want to just tack on our manual columns on sheet2 to sheet1 with no duplicates at the end of the month.

    There's also a recorded macro that I wanted to add which sets the print area and does some minor stuff. I wonder if I can add it right before the save command for the new workbook? Also- the environment is Excel 2003- I dunno if that limits what kind of macros will work.


    Thanks for your time!


    Edit: I just realized if I want to combine sheet1 with sheet2, I should add column headers to sheet1. I would probably have 2 rows on the top of sheet1 dedicated to column headers. just like it is on sheet2.

    Edit2: I fixed the attachment so the input sheet has 2 rows for the header like the output sheet.

    demo v2.xls


    tl;dr
    Combine columns A:AK on sheet1 (which has duplicated rows) with columns E:Q on sheet2- by matching the ID# column on each sheet (column E on Sheet1 against column C on sheet2). And save as a new workbook.
    Last edited by vandetta; 01-04-2013 at 04:17 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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