Question on Selection in vba

HunterN

Active Member
Joined
Mar 19, 2002
Messages
479
Hi,

I am wondering if there is a way using VBA, to change from having many
rows selected to only having the last row that is in the current selection?

For instance if there are five rows selected in column C, I want the next
vba code to be one that only activates the last row in that selection.

Thanks much,
Nancy
 

Some videos you may like

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
How about:

Code:
Cells(Rows.Count, "C").End(xlUp).Select

But there's usually no need to select. ;)

HTH,

Smitty
 

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,871
Hi HunterN

This statement will select the last cell in the first column of the currently selected range

Code:
Selection.Cells(Selection.Rows.Count, 1).Select

Remark: I'm 100% with Smitty. In most cases it's bad programming practice to select.

Hope this helps
PGC
 

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
Hi, guys,

from having many rows selected to only having the last row that is in the current selection
my interpretation is different
Code:
Sub test()
    With Selection
    .Resize(1).Offset(.Rows.Count - 1, 0).Select
    End With
End Sub
of course, talking with pgc01 and Pennysaver, usually you don't need to select

kind regards,
Erik
 

HunterN

Active Member
Joined
Mar 19, 2002
Messages
479
Thanks, that's what I needed.

I know I shouldn't select things, but in this case I needed to.

:)
 

Watch MrExcel Video

Forum statistics

Threads
1,114,673
Messages
5,549,351
Members
410,910
Latest member
DessertDiva
Top