Try with this:
Sub CheckAndCleanData()
Dim Ws1 As Worksheet
Dim Ws2 As Worksheet
Dim Ws3 As Worksheet
Dim Col1 As Long
Dim Col2 As Long
Dim Col3 As Long
Dim Row3 As Long
Dim HeaderText As String
Dim LastRow As Long
Dim Answer As Byte
Set Ws1 = Sheets("Data1")
Set Ws2 = Sheets("Data2")
Set Ws3 = Sheets("Data3")
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
LastRow = WorksheetFunction.Max(Ws1.Cells.SpecialCells(xlCellTypeLastCell).Row, Ws2.Cells.SpecialCells(xlCellTypeLastCell).Row)
For Col3 = 1 To Ws3.Cells(1, Ws3.Columns.Count).End(xlToLeft).Column
HeaderText = Ws3.Cells(1, Col3).Value
If HeaderText = "" Then GoTo NextHeader
For Col1 = 1 To Ws1.Cells(1, Ws1.Columns.Count).End(xlToLeft).Column
If Ws1.Cells(1, Col1).Value = HeaderText Then Exit For
Next Col1
For Col2 = 1 To Ws2.Cells(1, Ws2.Columns.Count).End(xlToLeft).Column
If Ws2.Cells(1, Col2).Value = HeaderText Then Exit For
Next Col2
If Col1 > Ws1.Cells(1, Ws1.Columns.Count).End(xlToLeft).Column _
Or Col2 > Ws2.Cells(1, Ws2.Columns.Count).End(xlToLeft).Column _
Then GoTo NextHeader
For Row3 = 2 To LastRow
If Ws1.Cells(Row3, Col1).Value = "" And Ws2.Cells(Row3, Col2).Value = "" Then Exit For
If Ws1.Cells(Row3, Col1).Value = Ws2.Cells(Row3, Col2).Value Then
Ws3.Cells(Row3, Col3).Value = Ws1.Cells(Row3, Col1).Value
Else
Application.ScreenUpdating = True
Answer = MsgBox("The values are different. To keep Data1 press yes, to keep Data2 press no, to enter new data press cancel. Data1 = " _
& Ws1.Cells(Row3, Col1).Value & " Data2 = " & Ws2.Cells(Row3, Col2).Value, vbYesNoCancel, "Check and Clean data")
If Answer = vbYes Then
Ws3.Cells(Row3, Col3).Value = Ws1.Cells(Row3, Col1).Value
ElseIf Answer = vbNo Then
Ws3.Cells(Row3, Col3).Value = Ws2.Cells(Row3, Col2).Value
Else
Ws3.Cells(Row3, Col3).Value = Application.InputBox("Enter new value", "Check and Clean Data")
End If
Application.ScreenUpdating = False
End If
Next Row3
NextHeader:
Next Col3
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
I hope that helps, I think it works as you needed.
Bookmarks