View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
David Godinger[_2_] David Godinger[_2_] is offline
external usenet poster
 
Posts: 15
Default VBA for Selecting Last Row in Range

On Sunday, October 25, 2020 at 3:25:24 PM UTC-7, Peter T wrote:
"David Godinger" wrote in message
On Sunday, October 25, 2020 at 12:05:51 PM UTC-7, Peter T wrote:
"David Godinger" wrote in message
Yes, getting the last cell of text or numbers in one column is easy,
but
that's not what I'm asking for.
OK try this -

Sub test()
Dim rngData As Range
Dim rngFound As Range

Set rngData = Range("B2:J20")

Set rngFound = rngData.Find("*", rngData.Cells(1), xlValues, , xlByRows,
xlPrevious)

If rngFound Is Nothing Then
MsgBox rngData.address & " is empty"
Else
MsgBox rngFound.Address
End If

End Sub

Peter T



OK, great! The message box found the correct cell. Could you please add a
line to select that cell?

rngFound.Select

If not on the activesheet start with -
rngFound.Parent.Parent.activate
rngFound.Parent.activate

Or use Application.Goto as I suggested earlier, better if you want to bring
the selected cell into the 'Visible.Range'.

Peter T


Hi Again Mr. T.,

The following works almost perfectly for me, except for an exception that may never even come up. The macro doesn't detect the contents of hidden columns.

Thanks so much for helping me! I really appreciate it!

Mr. G.

Sub gotoEndOfRangeOfAllDataLeft()

Dim rngData As Range
Dim rngFound As Range

Set rngData = Range("rangeOfAllDataLeft")
Set rngFound = rngData.Find("*", rngData.Cells(1), xlValues, , xlByRows, xlPrevious)
rngFound.Select

ActiveCell.Offset(1, 0).Select 'Move cursor down one row
Cells(ActiveCell.Row, 29).Select 'Move cursor to column AC on same row

End Sub