I'm trying to define a variable as the last row in a closed file. I understand how to make the value of a cell equal to a value in a closed workbook, but I can't figure out why it's not similar when defining a variable as the last row of a sheet in a closed workbook. I'm trying to get all of the data in the closed worksheet into the open worksheet but the number of lines of data that the closed sheet can have varies. Here's what I have right now:
Dim lastrow As Integer
Dim Path As String
Dim File As String
Dim Sheet As String
'Make variable for file server path so you don't have to type it a million times
Path = "\\A\B\C\"
File = "Closed Workbook.xlsm"
Sheet = "sheet name"
'Make cell A1 equal to the A1 cell in the Closed Workbook sheet
Range("A1").Formula = "='" & Path & "[" & File & "]" & Sheet & "'!RC"
'Define last row in Closed Workbook sheet
lastrow = "'" & Path & "[" & File & "]" & Sheet & "'!".UsedRange.SpecialCells(xlLastCell).Row
'Fill current sheet down to the last row in the Closed Workbook sheet
Selection.AutoFill Destination:=Range("A1:BD1" & lastrow)
And this is the part that throws up an error:
'Define last row in Closed Workbook sheet
lastrow = "'" & Path & "[" & File & "]" & Sheet & "'!".UsedRange.SpecialCells(xlLastCell).Row
I know there's a way to do it by opening the Closed Workbook, but there's got to be an easier way, right? Any help is much appreciated!
Bookmarks