There is an another approch to solve your problem.
You can use a "Name" of the collection "Names" to store
"the" last row of your sheet each time your workbook is
Deactivated... or Closed (Sub Workbook_BeforeClose(Cancel As Boolean)
Insert in the ThisWorkbook of your projectvba of your workbook
this code :
'-----------------------------
Private Sub Workbook_Deactivate()
Dim LastRow As String
On Error Resume Next
With Sheet1
LastRow = .Cells.Find(What:="*", _
LookIn:=xlValues, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
On Error GoTo 0
End With
ThisWorkbook.Names.Add "LastRow", LastRow, False
End Sub
'-----------------------------
Now, from any other workbook, you can easily read the value
of this "NAME" using this type of code :
'---------------------------------
Sub Test()
Dim LastRow As Long
LastRow = Application.ExecuteExcel4Macro("'C:\MyPath\MyWorkbook.xls'!LastRow")
End Sub
'---------------------------------
A fast and simple approach !
"Geoff K" <
[email protected]> a écrit dans le message de groupe de
discussion : (e-mail address removed)...
Hi
Thanks for the example. I have got it to work on a single field, the error
was caused simply by reading a text field not a numeric.
I now need to expand it to obtain the last row of the whole table. However
this wbook UsedRange is so bloated, AF50918 compared to S98, and the loop
used on duplicates is very slow even on a single field. I fear it will undo
all the run time advantage of not opening and closing the wbook.
But it is at least one way and worth further experimentation.
Geoff