Another one
Sub test()
Dim nr As Long, nc As Long, cel As Range, s As String
If LastDataCell(ActiveSheet, nr, nc, cel) Then
s = "Last data cell " & cel.Address & vbCr & _
"row " & nr & vbCr & "col " & nc
Else
s = "empty sheet"
End If
MsgBox s
End Sub
Function LastDataCell(ws As Worksheet, _
lastRow As Long, lastCol As Long, _
Optional rCell As Range) As Boolean
Dim X As Variant
On Error Resume Next
LastDataCell = True
With ws
lastRow = .Cells.Find("*", .Range("A1"), xlFormulas, _
xlPart, xlByRows, xlPrevious, 0).Row
lastCol = .Cells.Find("*", .Range("A1"), xlFormulas, _
xlPart, xlByColumns, xlPrevious, 0).Column
X = .Cells.Find("") 'reset Find
If Err.Number < 0 Then ' an empty sheet
lastRow = 1
lastCol = 1
LastDataCell = False
End If
Set rCell = .Cells(lastRow, lastCol)
End With
End Function
To reset the scrollbars, clear any formats below/right of the last data
cell, ie delete rows & columns. Then you'll probably need to call
ws.usedrange to fully reset (it'll get done when you save, close, re-open)
Regards,
Peter T
"Bob" wrote in message
...
Hi All:
I have two questions that are sort of related.
1-I was wondering is anyone knows in excel, how we could know, the last
row
and column on the spreadhseet that has any data in it?
2- Let's say that you have data on the Range A1:A20, and A1000. At this
point the vertical scroll bar is very small. Then if you delete A1000, is
there a way to reset the limits on the vertical scroll bar? In the
regular
VB, you have Scrolbar.min and scrolbar.max. Is there such a thing in VBA
for
Excel?
Thanks for your help.
Bob