Я не совсем уверен, хотите ли вы строку 46
или строку 42
.Ниже приведен подход и комментарии в коде для получения более подробной информации:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim wb As Workbook: Set wb = ThisWorkbook
Dim wsWatch As Worksheet: Set wsWatch = wb.Sheets("Sheet1") 'declare and set the sheet (change the name or use Target.Worksheet instead as needed)
Dim rngWatch As Range: Set rngWatch = wsWatch.Range("A46:CV46") 'declare and set the range to watch over
Dim arrWatch As Variant: arrWatch = rngWatch 'allocate the range to an array
Dim wsHistory As Worksheet: Set wsHistory = wb.Sheets("Sheet2") 'declare and set the sheet
With wsHistory
Dim lRow As Long: lRow = .Cells(.Rows.Count, "A").End(xlUp).Row 'get the last row in the history
Dim rngHistory As Range: Set rngHistory = .Range(.Cells(lRow, 1), .Cells(lRow, 100)) 'declare and set the range of the last populated row (last historic change)
End With
Dim arrHistory As Variant: arrHistory = rngHistory 'allocate the range to an array
Dim C As Long
'Only one row in the arrays, let's loop over the columns
For C = LBound(arrWatch, 2) To UBound(arrWatch, 2) 'for each column in the ranges
If arrWatch(1, C) <> arrHistory(1, C) Then 'if there is a mismatch
rngHistory.Offset(1) = rngWatch.Value 'allocate the values in the next free row
Exit For 'exit here if mismatch found
End If
Next C
End Sub
Возможно, это не идеальное решение, но я с нетерпением жду возможности увидеть другие решения ... между тем, я думаю, что этоделает то, что вы просили.