ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Find the last cell in a selected range? (https://www.excelbanter.com/excel-programming/391398-find-last-cell-selected-range.html)

J@Y

Find the last cell in a selected range?
 
I have a user selecting a range, how would I put the ending cell in the range
in a variable?

RB Smissaert

Find the last cell in a selected range?
 
dim rng as range

set rng = selection.cells(selection.cells.count)

RBS


"J@Y" wrote in message
...
I have a user selecting a range, how would I put the ending cell in the
range
in a variable?



J@Y

Find the last cell in a selected range?
 
I guess there's no function for it because End(xldown) only goes to the first
blank cell. Thanks for the smart solution

"RB Smissaert" wrote:

dim rng as range

set rng = selection.cells(selection.cells.count)

RBS


"J@Y" wrote in message
...
I have a user selecting a range, how would I put the ending cell in the
range
in a variable?




Bernie Deitrick

Find the last cell in a selected range?
 
Note that the code will not work if there are multiple areas selected. In that case:

Dim rng As Range
Set rng =
Selection.Areas(Selection.Areas.Count).Cells(Selec tion.Areas(Selection.Areas.Count).Cells.Count)

HTH,
Bernie
MS Excel MVP


"RB Smissaert" wrote in message
...
dim rng as range

set rng = selection.cells(selection.cells.count)

RBS


"J@Y" wrote in message
...
I have a user selecting a range, how would I put the ending cell in the range
in a variable?





Dave Peterson

Find the last cell in a selected range?
 
Check your previous post, too.

J@Y wrote:

I have a user selecting a range, how would I put the ending cell in the range
in a variable?


--

Dave Peterson

J@Y

Find the last cell in a selected range?
 
Thanks for the note.

"Bernie Deitrick" wrote:

Note that the code will not work if there are multiple areas selected. In that case:

Dim rng As Range
Set rng =
Selection.Areas(Selection.Areas.Count).Cells(Selec tion.Areas(Selection.Areas.Count).Cells.Count)

HTH,
Bernie
MS Excel MVP


"RB Smissaert" wrote in message
...
dim rng as range

set rng = selection.cells(selection.cells.count)

RBS


"J@Y" wrote in message
...
I have a user selecting a range, how would I put the ending cell in the range
in a variable?






Tom Ogilvy

Find the last cell in a selected range?
 
an additional note/added caution is that that method isn't reliable: (to
illustrate from the immediate window).

Set rng =
Selection.Areas(Selection.Areas.Count).Cells(Selec tion.Areas(Selection.Areas.Count).Cells.Count)
? rng.Address
$D$17
? selection.Address
$F$18:$G$21,$C$10:$E$14,$D$16:$D$17


I would have expected G21 to be the result. It depends on how the user
selects the range.

--
Regards,
Tom Ogilvy


"J@Y" wrote:

Thanks for the note.

"Bernie Deitrick" wrote:

Note that the code will not work if there are multiple areas selected. In that case:

Dim rng As Range
Set rng =
Selection.Areas(Selection.Areas.Count).Cells(Selec tion.Areas(Selection.Areas.Count).Cells.Count)

HTH,
Bernie
MS Excel MVP


"RB Smissaert" wrote in message
...
dim rng as range

set rng = selection.cells(selection.cells.count)

RBS


"J@Y" wrote in message
...
I have a user selecting a range, how would I put the ending cell in the range
in a variable?






All times are GMT +1. The time now is 09:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com