![]() |
Find last row can't find anything...
i got this from tek-tips forum but i can't seem to get it working... do
i have to add anything? i'm pretty new at coding so i'm still learning... what i'm basically trying to do is this: i have col A - R they're all different lengts... some are the same but usually there's one or 2 which are usually the longest... like, A might only be through row 17, but C may be all the way through 34, and so on... all i need is something that will find the longest column, go 3 cells down from that and select A# (# being the last row + 3) Sub FindLastRow() r = ActiveSheet.UsedRange.Rows.Count c = ActiveSheet.UsedRange.Columns.Count LastRow = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell) .Row End Sub --- Message posted from http://www.ExcelForum.com/ |
Find last row can't find anything...
Try something like this
Sub FindLastRow() Dim LastRow As Long If WorksheetFunction.CountA(Cells) 0 Then 'Search for any entry, by searching backwards by Rows. LastRow = Cells.Find(What:="*", After:=[A1], _ SearchOrder:=xlByRows, _ SearchDirection:=xlPrevious).Row MsgBox LastRow End If End Sub -- Regards Ron de Bruin (Win XP Pro SP-1 XL2000-2003) www.rondebruin.nl "aapp81" wrote in message ... i got this from tek-tips forum but i can't seem to get it working... do i have to add anything? i'm pretty new at coding so i'm still learning... what i'm basically trying to do is this: i have col A - R they're all different lengts... some are the same but usually there's one or 2 which are usually the longest... like, A might only be through row 17, but C may be all the way through 34, and so on... all i need is something that will find the longest column, go 3 cells down from that and select A# (# being the last row + 3) Sub FindLastRow() r = ActiveSheet.UsedRange.Rows.Count c = ActiveSheet.UsedRange.Columns.Count LastRow = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell) .Row End Sub --- Message posted from http://www.ExcelForum.com/ |
Find last row can't find anything...
hey, thanks for that sub... its actually very helpful b/c it was going
to be my next question... :) but its not exactly what i needed right now... i still need something that will go 3 rows down from the LastRow and select A# (# being LastRow + 3 cells down) --- Message posted from http://www.ExcelForum.com/ |
Find last row can't find anything...
Sub FindLastRow()
lastRow = ActiveSheet.UsedRange.Rows.Count Range("A" & lastRow+3).Select End Sub A more accurate method has been posted in the past Sub GetRealLastCell() Dim RealLastRow As Long Dim RealLastColumn As Long Range("A1").Select On Error Resume Next RealLastRow = _ Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row RealLastColumn = _ Cells.Find("*", [A1], , , xlByColumns, xlPrevious).Column Cells(RealLastRow, RealLastColumn).Select End Sub You could adapt this to Sub FindLastRow RealLastRow = _ Range("A:R").Find("*", [A1], , , xlByRows, xlPrevious).Row Range("A" & RealLastRow+3).Select End Sub -- Regards, Tom Ogilvy "aapp81" wrote in message ... i got this from tek-tips forum but i can't seem to get it working... do i have to add anything? i'm pretty new at coding so i'm still learning... what i'm basically trying to do is this: i have col A - R they're all different lengts... some are the same but usually there's one or 2 which are usually the longest... like, A might only be through row 17, but C may be all the way through 34, and so on... all i need is something that will find the longest column, go 3 cells down from that and select A# (# being the last row + 3) Sub FindLastRow() r = ActiveSheet.UsedRange.Rows.Count c = ActiveSheet.UsedRange.Columns.Count LastRow = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell) .Row End Sub --- Message posted from http://www.ExcelForum.com/ |
Find last row can't find anything...
Try this
Sub Test() Dim LastRow As Long If WorksheetFunction.CountA(Cells) 0 Then LastRow = Cells.Find(What:="*", After:=[A1], _ SearchOrder:=xlByRows, _ SearchDirection:=xlPrevious).Row Range(Cells(LastRow, 1), Cells(LastRow + 3, 1)).Select End If End Sub -- Regards Ron de Bruin (Win XP Pro SP-1 XL2000-2003) www.rondebruin.nl "aapp81" wrote in message ... hey, thanks for that sub... its actually very helpful b/c it was going to be my next question... :) but its not exactly what i needed right now... i still need something that will go 3 rows down from the LastRow and select A# (# being LastRow + 3 cells down) --- Message posted from http://www.ExcelForum.com/ |
Find last row can't find anything...
|
All times are GMT +1. The time now is 07:07 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com