ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Ctrl + End (https://www.excelbanter.com/excel-programming/273587-re-ctrl-end.html)

Ron de Bruin

Ctrl + End
 
Ctrl+End is not always give you the good result
I use a function to find the last row and column with data

You can use something like this then for the activesheet
Application.Goto ActiveSheet.Cells(LastRow(ActiveSheet), Lastcol(ActiveSheet)), scroll:=True


Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function

Function Lastcol(sh As Worksheet)
On Error Resume Next
Lastcol = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
On Error GoTo 0
End Function

See this page also
http://www.contextures.com/xlfaqApp.html#Unused


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"Cathy Myers" wrote in message ...
Hi,

Is there any way to programmatically control how Ctrl+End
works? My spreadsheet pulls from a database, and I'd like
for Ctrl+End to take them to the last cell to which data
has been returned. Thanks in advance.

Yours,
C.M.





All times are GMT +1. The time now is 05:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com