Reputation: 1496
I am trying this code to find out the last row-
msgbox objExcel.ActiveWorkbook.Sheets(1).Range("A" & Rows.Count).EndXL(up).Row
But i am keep getting this error-
Object required: Rows
Upvotes: 1
Views: 14117
Reputation: 1
This might work:
dim last as integer
ActiveCell.SpecialCells(xlLastCell).Select
last = ActiveCell.SpecialCells(xlLastCell).Row
Upvotes: 0
Reputation: 149277
Is this what you are trying?
Dim oXLApp, wb, ws
'~~> Define xlUp
Const xlUp = -4162
Set oXLApp = CreateObject("Excel.Application")
oXLApp.Visible = True
'~~> Open file. Chnage path as applicable
Set wb = oXLApp.Workbooks.Open("C:\Sample.xlsx")
Set ws = wb.Worksheets(1)
With ws
MsgBox .Range("A" & .Rows.Count).End(xlUp).Row
End With
Also notice the use of Worksheets
rather than Sheets
See this link for explanation.
Upvotes: 0
Reputation: 2910
Try
objExcel.ActiveWorkbook.Sheets(1).Range("A" & Rows.Count).End(xlUp).Row
It's just your End(xlUp) part that's wrong
Upvotes: 1