Skip to main content

Hello all.

Anyone know how to find the last cell in an opened Excel file from the script editor?

In Excel it would be: .SpecialCells(xlCellTypeLastCell).Row.

Thank you in advance.


#Rumba

Hello all.

Anyone know how to find the last cell in an opened Excel file from the script editor?

In Excel it would be: .SpecialCells(xlCellTypeLastCell).Row.

Thank you in advance.


#Rumba

Try this

path = "C:\\temp\\yourexcel.xlsx"
   
   
Set XLApp = CreateObject("Excel.Application")   
   
Set XLBook = XLApp.Workbooks.Open(path)         
   
Set XLSheet = XLBook.Worksheets("Sheet1")       
    XLSheet.Activate                               
' Activate the Worksheet
    XLSheet.Application.Visible = True 
   
   
    lastColumn
= XLSheet.UsedRange.Column - 1 XLSheet.UsedRange.Columns.Count
    lastRow
= XLSheet.UsedRange.Row - 1 XLSheet.UsedRange.Rows.Count

MsgBox lastRow
MsgBox lastColumn