Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default VBA for Selecting Last Row in Range

I'd like to name a range and go to the last row with data in that range.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default VBA for Selecting Last Row in Range

"David Godinger" wrote in message
I'd like to name a range and go to the last row with data in that range.


one way -

Dim rng As Range, rngBR As Range

Set rng = ActiveSheet.Range("B2:Z100")
With rng
Set rngBR = .Cells(.Rows.Count, .Columns.Count)
End With
'Debug.Print rngBR.Address
Application.Goto rngBR

Peter T


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default VBA for Selecting Last Row in Range

The macro took me to the last cell (the lower right of the entire range). By the way, the lower half of the range had no text or numbers in it.

However, there was formatting in all cells of the range for color, number, and border. Could it be that the macro considers the formatting as data? If so, would it be possible for the macro to work only on numbers, dates, and text?

Thanks!

Dave G.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default VBA for Selecting Last Row in Range

"David Godinger" wrote in message
The macro took me to the last cell (the lower right of the entire range).
By the way, the lower half of the range had no text or numbers in it.

However, there was formatting in all cells of the range for color, number,
and border. Could it be that the macro considers the formatting as data?
If so, would it be possible for the macro to work only on numbers, dates,
and text?


Sorry I misread you wanted the last row 'with data'.

It would simplify things if you wanting the last cell in a specified column
(rather than all columns that includ data, for example the in the first
column of the given range - If that's that an option try this

last data cell in first column of the range

lastRow = rng.Offset(rng.Rows.Count, 1 - 1).Cells(1).End(xlUp).Row
' lastRow = actual row

' or last row with data in col-1 of the range
lastRow = lastRow - rng.Rows(1).Row + 1
Debug.Print rng(lastRow, 1).Address

Peter T


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default VBA for Selecting Last Row in Range

Yes, getting the last cell of text or numbers in one column is easy, but that's not what I'm asking for.

Again, I've appreciated your thoughts, thanks.


On Sunday, October 25, 2020 at 11:11:56 AM UTC-7, Peter T wrote:
"David Godinger" wrote in message
The macro took me to the last cell (the lower right of the entire range).
By the way, the lower half of the range had no text or numbers in it.

However, there was formatting in all cells of the range for color, number,
and border. Could it be that the macro considers the formatting as data?
If so, would it be possible for the macro to work only on numbers, dates,
and text?

Sorry I misread you wanted the last row 'with data'.

It would simplify things if you wanting the last cell in a specified column
(rather than all columns that includ data, for example the in the first
column of the given range - If that's that an option try this

last data cell in first column of the range

lastRow = rng.Offset(rng.Rows.Count, 1 - 1).Cells(1).End(xlUp).Row
' lastRow = actual row

' or last row with data in col-1 of the range
lastRow = lastRow - rng.Rows(1).Row + 1
Debug.Print rng(lastRow, 1).Address

Peter T



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default VBA for Selecting Last Row in Range

"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


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 12: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 08:05 PM


All times are GMT +1. The time now is 01:29 AM.

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

About Us

"It's about Microsoft Excel"