Results 1 to 3 of 3

Find last row in closed workbook using file path name

Threaded View

  1. #1
    Registered User
    Join Date
    06-04-2012
    Location
    Waterloo, iA
    MS-Off Ver
    Excel 2007
    Posts
    14

    Find last row in closed workbook using file path name

    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!
    Last edited by amazingg64; 08-27-2012 at 09:21 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1