View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
indiana1138 indiana1138 is offline
external usenet poster
 
Posts: 5
Default .Cells.SpecialCells(xlLastCell)

Hello Simon,

Other folks have found that Excel does not work as advertised in this
respect. Try this code for something that might work:

Function LastCell(Optional ws As Worksheet) As Range
If ws Is Nothing Then Set ws = ActiveSheet
Set Rng = ws.Cells
Set LastCell = Rng(1)
On Error Resume Next
Set LastCell = Intersect( _
Rng.Find("*", Rng(1), xlValues, xlWhole, xlByRows, _
xlPrevious).EntireRow, _
Rng.Find("*", Rng(1), xlValues, xlWhole, xlByColumns, _
xlPrevious).EntireColumn)
End Function

Hope this helps,

Bob