View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Activate last cell in selected range - an example

If B1 and AA1 are selected, this chooses B1

if B10, D1, AA1 are selected this chooses D1

But besides the weakness in an alphabetic comparison, the defintion of what
is the last cell remains a problem.

Maybe one needs to use polar coordinates. (but which is dominant, angle or
distance).

--
Regards,
Tom Ogilvy

"Norman Jones" wrote in message
...
Hi Doug,

I came up with something like yours, but it always selects the bottom
right
corner of the last area selected


Ageed

The only issue I have with DFFU's is that it sometimes chooses a cell
outside of any of the area


Also agreed.

The following seemed to resolve the above and work consistently with
single/multiple area ranges, independently of selection sequence or area
intersection/overlap:

Sub Test1()
Dim Rng1 As Range, Rng2 As Range
Dim i As Long

With Selection
Set Rng1 = .Areas(1)(.Areas(1).Cells.Count)
For i = 2 To .Areas.Count
Set Rng2 = .Areas(i)(.Areas(i).Cells.Count)
If Rng2.Address Rng1.Address _
Then Set Rng1 = Rng2
Next
End With
Rng1.Activate
End Sub

---
Regards,
Norman



"Doug Glancy" wrote in message
...
Norman,

I came up with something like yours, but it always selects the bottom
right
corner of the last area selected, i.e., if I last area I selected

("last"
temporally speaking) is above and to the left of other selections, it
still
activates it's last cell.

The only issue I have with DFFU's is that it sometimes chooses a cell
outside of any of the area, e.g., if you select A1:B3 and D1:D2 it
"squares
the corner." However, I can't come up with anything better.

Regards,

Doug Glancy

"Norman Jones" wrote in message
...
Hi DataFreakFromUtah,

In addition to Bob's response, for a multiple area selection, try:

Sub Tester()
Dim i As Long
i = Selection.Areas.Count

With Selection
.Areas(i).Cells(.Areas(i).Cells.Count).Activate
End With
End Sub


---
Regards,
Norman



"DataFreakFromUtah" wrote in message
om...
No question here, just a procedure for the archive.

Search critera: activate the last cell in a selection
select last cell in range
select last cell in selection
activate last cell in range


Sub SelectActivateLastCellInSelectedRange()
'Activates the last cell in the selected range but keeps the
'same range selected


Dim LastRow As Variant
Dim LastCol As Variant
Dim TempRow As Variant
Dim TempCol As Variant
Dim LastCell As Range
Dim A As Range


LastRow = 1
LastCol = 1
ActiveWorkbook.Activate
For Each A In Selection.Areas
TempRow = A.Range("A1").Offset(A.Rows.Count - 1, 0).Row
If TempRow LastRow Then LastRow = TempRow
TempCol = A.Range("A1").Offset(0, A.Columns.Count - 1).Column
If TempCol LastCol Then LastCol = TempCol
Next A
Set LastCell = Cells(LastRow, LastCol)
LastCell.Activate


End Sub