ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   How do I create a macro that will select a range that can vary in (https://www.excelbanter.com/excel-discussion-misc-queries/141481-how-do-i-create-macro-will-select-range-can-vary.html)

smokief

How do I create a macro that will select a range that can vary in
 
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.

Dave Peterson

How do I create a macro that will select a range that can vary in
 
This selects the activecell to the last used cell in that column:

with activesheet
.range(activecell, .cells(.rows.count,activecell.column).end(xlup)).s elect
end with

smokief wrote:

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.


--

Dave Peterson

Gord Dibben

How do I create a macro that will select a range that can vary in
 
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

On Thu, 3 May 2007 11:08:01 -0700, smokief
wrote:

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.




All times are GMT +1. The time now is 08:50 PM.

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