I am working currently on an Excel-file which consists of 3 sheets. The three sheets consist of following, firstly the sheet "Datenquelle", secondly the sheet "Datenunterschied" and thirdly the sheet "Daten".
All three sheets contain identical column names and similar data. I want to highlight the differences of the data in "Datenquelle" and "Daten" into the sheet "Datenunterschied" via a VBA Macro.
The reference point should be the column "Identifier".
As you can see, the sheet "Daten" contains four datasets with following Identifier numbers:
6257 - 6258 - 6259 - 6260
The sheet "Datenquelle" contains six Identifier numbers:
6257 - 6258 - 6259 - 6260 - 6261 - 6268
The goal would be that all the datasets which are not contained in sheet "Daten", but are contained "Datenquelle", should be taken via a VBA Macro into the sheet "Datenunterschied". In my example, those would be the datasets which following Identifiers "6261" & "6268". The whole cell of the datasets "6261" & "6268" should be transferred to "Datenunterschied".
I tried following Macro, but it didn't produce the right outcome.
Sub Unterschied()
Dim CompareRange As Object, x As Object, y As Object
Dim lastRow As Integer
Set CompareRange = Sheets("Datenquelle").Range("H2:H" & Sheets("Datenquelle").Cells(Rows.Count, _
9).End(xlUp).Row)
For Each x In Sheets("Daten").Range("H2:H" & Sheets("Daten").Cells(Rows.Count, 9).End(xlUp). _
Row)
For Each y In CompareRange
If y <> x Then
lastRow = Sheets("Datenunterschied").Cells(Rows.Count, 1).End(xlUp).Row + 1
Sheets("Datenunterschied").Cells(lastRow, 9).Value = x.Value
Sheets("Datenunterschied").Cells(lastRow, 10).Value = x.Offset(0, 1).Value
Sheets("Datenunterschied").Cells(lastRow, 11).Value = x.Offset(0, 2).Value
Sheets("Datenunterschied").Cells(lastRow, 8).Value = x.Offset(0, -1).Value
Sheets("Datenunterschied").Cells(lastRow, 7).Value = x.Offset(0, -2).Value
Sheets("Datenunterschied").Cells(lastRow, 6).Value = x.Offset(0, -3).Value
Sheets("Datenunterschied").Cells(lastRow, 5).Value = x.Offset(0, -4).Value
Sheets("Datenunterschied").Cells(lastRow, 4).Value = x.Offset(0, -5).Value
Sheets("Datenunterschied").Cells(lastRow, 3).Value = x.Offset(0, -6).Value
Sheets("Datenunterschied").Cells(lastRow, 2).Value = x.Offset(0, -7).Value
Sheets("Datenunterschied").Cells(lastRow, 1).Value = x.Offset(0, -8).Value
End If
Next y
Next x
End Sub
I have provided the data in here:
https://www.herber.de/bbs/user/137783.xlsm
Greetings Kanime