In the following code, the "Sheets.Count" in "Master.Activate" works only when the "Source" workbook is manually selected by mouse click before running the macro. Otherwise "Master.Activate" will activate the first worksheet of "Master" workbook instead of performing Sheets.Count
and selecting the last sheet. That basically means that the macro has to be run from "Master" workbook but only after clicking on "Source" workbook. I would be grateful for any suggestions on how to fix that.
Dim Source As Worksheet
Set Source = Workbooks("Source.xlsx").Worksheets("Settlements")
Dim Master As Worksheet
Set Master = Workbooks("Master Bonviva.xlsm").Worksheets(Sheets.Count)
Source.Activate
For Each cell In Source.Columns("M").Cells
If Not IsEmpty(cell) Then
Master.Activate
For Each cell2 In Master.Columns("J").Cells
If Not IsEmpty(cell2) Then
If cell = cell2 Then
cell2.Offset(0, 9).Value = cell.Offset(0, -2).Value
cell2.Offset(0, 8).Value = cell.Offset(0, -8).Value
End If
End If
Next cell2
End If
Next cell
End Sub
Regards, Bartek