Hi all!
I'm at a loss here... I have a workbook called UPC List.xls. I'm unable to save it as a .xlsx because it is auto generated and I can only specify Excel and not what version. I open the UPC List.xls workbook and then I go through each tab of that workbook and paste it into a worksheet in another workbook. I get through the first two sheets fine but when it gets to the 3rd sheet (which isn't the last in this instance) of UPC List.xls I get a debug error on the line where I determine the last row of the spreadsheet.
Sub Import()
Dim N As Long
Dim Entry_Book As String
Dim First_Row As Integer
Dim Last_Row As Long
Dim Last_Row1 As Long
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Entry_Book = ThisWorkbook.Name
Last_Row1 = Workbooks(Entry_Book).Sheets("Item Lookup").Range("A" & Rows.Count).End(xlUp).Row
Workbooks.Open Filename:="UPC List.xls"
Windows("UPC List.xls").Activate
For N = 1 To ActiveWorkbook.Worksheets.Count
If N = 1 Then
First_Row = Workbooks("UPC List.xls").Sheets(N).Range("B1").End(xlDown).Row
Else
First_Row = 1
End If
Last_Row = Workbooks("UPC List.xls").Sheets(N).Range("B" & Rows.Count).End(xlUp).Row 'debug error is here when N = 3
Workbooks("UPC List.xls").Sheets(N).Range("B" & First_Row & ":D" & Last_Row).Copy
Workbooks(Entry_Book).Sheets("Item Lookup").Range("A" & Last_Row1).PasteSpecial Paste:=xlPasteAll
Last_Row1 = Workbooks(Entry_Book).Sheets("Item Lookup").Range("A" & Rows.Count).End(xlUp).Row + 1
Next N
Windows("UPC List.xls").Close SaveChanges = False
End Sub
Display More
The problem workbook is too large to attach to this post but essentially, all of the tabs except for the first and the last all have 65,535 rows in them so not sure why it would work on the second tab but not the third.
Any help would be much appreciated!