How do I create a macro that will select a range that can vary in

G

Guest

In Excel, the keystrokes Shift+End+Arrow(any direction) selects the data from
the cell where the keystroke was invoked to the end of the data (in whichever
direction was indicated).
I used these keystrokes to create a macro to select data in a particular
column. It worked fine on my test file. However, if I use that same macro on
a file with a different number of data rows, the macro does not make the
selection in the same manner.
Whatever cells were selected on the recording is what is included in the
macro coding. Is there a way to edit the macro where it will mimic the
Shift+End+Arrow keystrokes? I want to select the data in a column, not a
specific hard-coded cell range.
 
D

Dave Peterson

This selects the activecell to the last used cell in that column:

with activesheet
.range(activecell, .cells(.rows.count,activecell.column).end(xlup)).select
end with
 
G

Gord Dibben

Sub select_alldown()

'select to bottom of selected column(s)
Set myRange = Range(Selection, Cells(Rows.Count, Selection.Column).End(xlUp))
MsgBox "Range selected is " & myRange.Address

End Sub


Gord Dibben MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top