View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Rob[_5_] Rob[_5_] is offline
external usenet poster
 
Posts: 25
Default Last cell determined different in XP/2003 as in 2000

Hello FellowNewsgroupReaders,

I adapted the 'last cell' macro from David McRitchie OR Chip Pearson (sorry
guys, I couldn't find it back eather).

This macro looks for the actual last filled cell in a sheet. It works
wonderful! Until now, that is.

In a sheet I created a last row that will not be used, just for a reference
as the last row. All other items are added before this row. I filled it with
the text "Last hidden row" and it is hidden. The sheet is protected with a
password. The 'stdLastCell' macro always tells me what row that is.
Now in Excel 2000 this all works fine. In Excel XP and 2003 however the las
row reported is NOT the hidden last row but the visible last row. If I set
off the protection of the sheet it will work fine.

Here's my macro's:

*************
Sub FindLast

Dim Test
Test = stdLastCell("Sheet1").Row

End sub

Function stdLastCell(strSheetname) As Range

' Returns the real last cell

Dim intLastRow As Integer
Dim intLastCol As Integer
Dim wsSearch As Worksheet
Set wsSearch = Sheets(Worksheets(strSheetname).Index)
' Error-handling
On Error Resume Next
With wsSearch
' find the real last row
intLastRow = .Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByRows).Row
' find the real liast column
intLastCol = .Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByColumns).Column
End With
'
Set stdLastCell = wsSearch.Cells(intLastRow, intLastCol)
End Function
*********

Any ideas why this is a difference?

Rob