Results 1 to 3 of 3

Macro for copying rows in sheet1 to end of existing rows in sheet2 based on criteria

Threaded View

Karl Gustaf Karsten Macro for copying rows in... 10-21-2015, 04:32 PM
mehmetcik Re: Macro for copying rows in... 10-21-2015, 06:25 PM
Karl Gustaf Karsten Re: Macro for copying rows in... 10-22-2015, 04:19 AM
  1. #1
    Registered User
    Join Date
    04-20-2015
    Location
    Norway
    MS-Off Ver
    360
    Posts
    24

    Macro for copying rows in sheet1 to end of existing rows in sheet2 based on criteria

    Hi there!
    I’m struggling with the last part(s) of a project.

    I have two sheets with data and both contain a row specific ID in all rows of column A. The matching ID can be found in only one row in each sheet. I’m trying to merge rows from the two sheets if they contain the same ID in column A.

    Sheets: “Data1”, “Data2”, and “Merged Data”
    The idea is to organize the “Merged Data” sheet like this:
    Data from “Data1” in the first 62 columns, one blank column, then the data from “Data2” in the next xx columns.

    Problem:
    - The matching IDs are in random rows.
    - There is data in an unknown number of columns in “Data2” (however, no more than 30)
    - The number of rows is unknown in both “Data1” and “Data2”.

    I’ve attached a short example of the workbook, and included how I picture the result.
    The code I’ve managed to put together only inputs the new sheet and gets me the headers – I really have no clue on how to get the rest.
    Sub Merge_Data()
    
    Dim MySheetName As String
        MySheetName = "Merged Data"
        Sheets("Data1").Copy After:=Sheets("Data1")
        ActiveSheet.Name = MySheetName
    
    Dim source As Worksheet
    Dim destination As Worksheet
    Dim emptyColumn As Long
        
        Set source = Sheets("Data2")
        Set destination = Sheets("Merged Data")
    
        emptyColumn = destination.Cells(1, destination.Columns.Count).End(xlToLeft).Column
            If emptyColumn > 1 Then
            emptyColumn = emptyColumn + 1
            End If
    
        source.Range("A1:BA1").Copy destination.Cells(1, emptyColumn + 1)
    
        Worksheets("Merged Data").Cells(1, emptyColumn).Value2 = "Compatible Data2 data-->"
    
    End Sub
    I can complete the project if someone can help me with this - And, of course, I’ll be very thankful!
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. automatically copying rows to an existing spreadsheet based on criteria
    By Jocatlett in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-30-2013, 07:21 PM
  2. Replies: 2
    Last Post: 10-16-2012, 11:34 AM
  3. [SOLVED] macro to copy the formulas in Sheet2 to as many rows as rows available in Sheet1
    By flakedew in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 06-21-2012, 04:52 AM
  4. Replies: 3
    Last Post: 06-06-2012, 05:36 AM
  5. [SOLVED] Copying Data from Sheet1 to sheet2 based on criteria for copy
    By pprane in forum Excel General
    Replies: 1
    Last Post: 04-22-2012, 02:32 AM
  6. Copying Data from Sheet1 to sheet2 based on criteria for copy
    By pprane in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-22-2012, 02:07 AM
  7. Help! Hiding rows in sheet2 based on values in sheet1
    By Oti in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-23-2011, 12:47 PM
  8. Macro to copy values from Sheet1 to Sheet3, based on criteria in Sheet2
    By John74 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-13-2010, 04:55 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