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!
Bookmarks