Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default How to get the last cell within a selection range?

Hi, all

Is any method could to return the last cell's address within current
selection?

ex: i select from A2 to B5, then it will return B5


Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to get the last cell within a selection range?

Option Explicit
Sub test1()

Dim myRng As Range
Set myRng = ActiveSheet.Range("a2:b5")
With myRng
MsgBox .Cells(.Cells.Count).Address
End With

End Sub

'multi-area range????
Sub test2()

Dim myRng As Range
Set myRng = ActiveSheet.Range("a2:b5,x9:z12")

With myRng
With .Areas(.Areas.Count)
MsgBox .Cells(.Cells.Count).Address
End With
End With

End Sub

OKLover wrote:

Hi, all

Is any method could to return the last cell's address within current
selection?

ex: i select from A2 to B5, then it will return B5

Thanks


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default How to get the last cell within a selection range?

Cool ~ Dave! you are my hero. :D

when i select from a2 to d5 it returns d5 <== this is correct.
but when i select from d5 to a2, it should returns a2 not d5


"Dave Peterson" wrote:

Option Explicit
Sub test1()

Dim myRng As Range
Set myRng = ActiveSheet.Range("a2:b5")
With myRng
MsgBox .Cells(.Cells.Count).Address
End With

End Sub

'multi-area range????
Sub test2()

Dim myRng As Range
Set myRng = ActiveSheet.Range("a2:b5,x9:z12")

With myRng
With .Areas(.Areas.Count)
MsgBox .Cells(.Cells.Count).Address
End With
End With

End Sub

OKLover wrote:

Hi, all

Is any method could to return the last cell's address within current
selection?

ex: i select from A2 to B5, then it will return B5

Thanks


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default How to get the last cell within a selection range?

OK, I got the answer by myself as below:

Sub test2()

With Selection.Areas(Selection.Areas.Count)
If ActiveCell.Address = .Cells(.Cells.Count).Address Then
Debug.Print .Cells(1).Address
Else
Debug.Print .Cells(.Cells.Count).Address
End If
End With

End Sub

"OKLover" wrote:

Cool ~ Dave! you are my hero. :D

when i select from a2 to d5 it returns d5 <== this is correct.
but when i select from d5 to a2, it should returns a2 not d5


"Dave Peterson" wrote:

Option Explicit
Sub test1()

Dim myRng As Range
Set myRng = ActiveSheet.Range("a2:b5")
With myRng
MsgBox .Cells(.Cells.Count).Address
End With

End Sub

'multi-area range????
Sub test2()

Dim myRng As Range
Set myRng = ActiveSheet.Range("a2:b5,x9:z12")

With myRng
With .Areas(.Areas.Count)
MsgBox .Cells(.Cells.Count).Address
End With
End With

End Sub

OKLover wrote:

Hi, all

Is any method could to return the last cell's address within current
selection?

ex: i select from A2 to B5, then it will return B5

Thanks


--

Dave Peterson

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
Cell Range Selection Color WCMOUSER Excel Discussion (Misc queries) 1 October 18th 08 04:51 PM
Individual cell selection in a range Riddler Excel Discussion (Misc queries) 3 December 8th 06 10:26 PM
Selection range to last non empty cell Jaan Excel Programming 4 November 20th 05 07:56 AM
Drop Down List Selection... Then go to The Cell / Range John[_78_] Excel Programming 3 October 30th 04 12:09 AM
Cell range selection after calculation Tom Ogilvy Excel Programming 0 November 12th 03 06:10 PM


All times are GMT +1. The time now is 04:12 PM.

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"