Hallo,
I have 2 workbooks. A and B. A = source, B = Target. Each of them has sheets with the same names. The task is to copy a certain range from A and insert it in a cell below the last occupied one. My code is as follows but it fails to work and I couldn't troubleshoot. could you pls help.
Error appears at
. Error = "91", saying object variable or with block variable no set.
I have 2 workbooks. A and B. A = source, B = Target. Each of them has sheets with the same names. The task is to copy a certain range from A and insert it in a cell below the last occupied one. My code is as follows but it fails to work and I couldn't troubleshoot. could you pls help.
Error appears at
Code:
lastRow = WBb.Sheets(sh.Name).Cells(Rows.Count, "B").End(xlUp).row+1
Code:
Sub FromA2B()
Dim WBa As Workbook
Dim WBb As Workbook
Dim sh As Worksheet
Dim lastRow As Range
Set WBa = ThisWorkbook
Set WBb = Workbooks("SWDP June 2010 - May 2017 (Oil and WI wells).xlsx")
For Each sh In WBa.Worksheets
sh.Range("B9:Z39").Copy
lastRow = WBb.Sheets(sh.Name).Cells(Rows.Count, "B").End(xlUp).row+1
lastRow.Select
Selection.Insert Shift:=xlDown
Application.CutCopyMode = False
Next sh
End Sub
Last edited: