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.
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
(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.
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.
Two related discoveries may as well be of interest to future visitors.
Selection.EntireColumn.Insertand 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).