Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #11   Report Post  
Old October 26th 20, 04:48 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Mar 2012
Posts: 15
Default VBA for Selecting Last Row in Range

On Monday, October 26, 2020 at 1:48:09 AM UTC-7, Peter T wrote:
"David Godinger" wrote in message
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

No need to Select three times -
Cells(rngFound.Row + 1, 29).Select

Indeed Find does't work with look in hidden columns, various other ways
depending on your overall scenario.

PT


Thanks again! The following now does the job very well for me!

Sub gotoEndOfRangeOfAllDataOnLeft1()

' *** Thanks to Peter T
' *** Who on Sunday, Oct. 25, 2020, patiently created this macro for me
' *** On the newsgroup https://groups.google.com/g/microsof...el.programming

'This macro moves the cursor to the bottom of all columns in the range with text or numbers
'And then moves the cursor down one row and to a specific column

Dim rngData As Range
Dim rngFound As Range

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

End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Proper syntax for selecting a range using cells instead of range JasonK[_3_] Excel Programming 4 July 22nd 09 07:01 AM
Selecting range in list of range names depending on a cell informa Courreges Excel Discussion (Misc queries) 2 June 19th 06 10:59 AM
Help please in selecting range dependent on another range MickJJ Excel Programming 2 January 10th 05 01:01 PM
Selecting a Range inside a range hcova Excel Programming 0 July 13th 04 03:26 PM
Selecting a range PCOR Excel Programming 4 December 27th 03 09:05 PM


All times are GMT +1. The time now is 10:18 PM.

Powered by vBulletin® Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright ©2004-2020 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"

 

Copyright © 2017