Hello, I need to copy data from one multi-sheet workbook to another multi-sheet workbook. I entered the names of the sheets permanently. As for the data from the sheets, they can change every month, so I can't copy a fixed range. I need to use lRow and lCol for each sheet but I have no idea how to do it. Here is some example code which is not working well, it is showing errors because lRow and lCol are working wrong. Maybe there is a more efficient solution? Maybe a better solution would be to do it without variables?
VBA Code:
Dim Workbook1 As Workbook
Dim lRow As Long
Dim lCol As Long
lRow = Cells(Rows.Count, 1).End.(xlUp).Row
lCol = Cells(1, Columns.Count).End.(xlToLeft).Column
With Workbook1
With .Sheets("A")
.Range(.Cells(2, 1), .Cells(lRow, lCol)).Copy
ThisWorkbook.Sheets("Ark1").Range("A2").PasteSpecial xlPasteValues
End With
With .Sheets("B")
.Range(.Cells(2, 1), .Cells(lRow, lCol)).Copy
ThisWorkbook.Sheets("Ark2").Range("A2").PasteSpecial xlPasteValues
End With
End With