• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

EXCEL VBA Get the last row from a closed workbook WITHOUT opening it

Status
Not open for further replies.

absolute.ivor

New Member
I want to get the last used row of a workbook without opening the workbook. Opening and closing the workbook, even sight unseen, is unacceptable.

The 2002 solution offered by Andrew Poulsom (https://www.mrexcel.com/forum/excel-questions/155993-last-row-used-closed-workbook-sheet.html ) but requires entry of a worksheet. I need the same code without using a worksheet to get the last row number.

Andrews code follows:

Code:
Sub Test()
' file name, sheet name and column number - change to suit
Const FName As String = "P:\TEMP\MrExcel\FileLinks\[MyFile.xls]"
Const ShName As String = "Sheet1"
Const ColNo As Integer = 1
Dim ShNew As Worksheet
Dim LastRow As Long
Application.DisplayAlerts = False
Set ShNew = Worksheets.Add
With ShNew.Range("A1")
.FormulaR1C1 = "=COUNTA('" & FName & ShName & "'!C" & ColNo & ")"
LastRow = .Value
End With
ShNew.Delete
Application.DisplayAlerts = True
MsgBox LastRow
End Sub
 
Last edited by a moderator:
Duplicated with this:
This thread is closed.
 
Status
Not open for further replies.
Back
Top