How do I move the selection down one row in Excel 2007?
Is there a way to move a selected range to the next row?
Let's say I have "E9:H9" selected and want the selection to move to "E10:H10". Is there a shortcut for it? The selection should not be extended but moved one row down.
It sounds like you just need something like this:
Sub moveselection()
Selection.Offset(1, 0).Select
End Sub
This will move your selection one row down without changing the size of the selection.
(a) That code doesn't move down one row as per question
(b) It will work on only the first row of a selection, did you want it to work on a multiple row selection ?
(c) Rather than call a sub for this you could run it automatically by right clicking your mouse - you can do this by adding right clicking your sheet tab, View Code, and pasting in the code below
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
On Error Resume Next
Range("E" & CStr(Selection.Row) & ":" & "GN" & CStr(Selection.Row)).Select
End Sub
An alternative that uses named arguments, and is, therefore, much clearer,is something like this.
ActiveCell.Offset(rowOffset:=1, columnOffset:=0).Activate
A positive rowOffset moves the selection down the sheet, a negative rowOffset moves up the specified number of rows, and a zero offset leaves the row in which the selection resides unchanged.
Likewise, positive offsets move the selection to the right, while negative offsets move it left. Zero, of course, leaves the column unchanged.
See Range.Offset Property (Excel)
Two related discoveries may as well be of interest to future visitors.
- Do the following to insert a column.
Selection.EntireColumn.Insert
and beware Range.Insert, which raises runtime error 1004, at least in some circumstances, such as protected worksheets (even with column insertion permitted while it is protected). - The method just described leaves the insertion point in the new column, which I didn't notice until I came here in search of a method to move the selection (only to discover that I didn't need it!).