7

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.

4
  • I suppose you want to retain the data?
    – Sathyajith Bhat
    Oct 4, 2011 at 9:28
  • 1
    Simple Cut & Paste will work for you, select your data, click "Ctrl+X", now click on cell address E10:H10 and press "Ctrl+V" , it's done...
    – Random Guy
    Oct 4, 2011 at 9:41
  • Hi. That's not what I had in mind. But I solved it using a macro. Thx anyway.
    – user48604
    Oct 4, 2011 at 9:54
  • @user48604 please post the macro as an answer.
    – Sathyajith Bhat
    Oct 4, 2011 at 10:08

4 Answers 4

13

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.

3

(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
1

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.

  1. 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).
  2. 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!).
0

Ok,

The cursor has to be in the row and the ranges "E" and "GN" need adjustement for different columns but it saves me some time:

Sub SelectRange()

  Dim RowNumber As Integer

  RowNumber = Selection.Row
  Range("E" & CStr(RowNumber) & ":" & "GN" & CStr(RowNumber)).Select

End Sub

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.