Search code examples
vbaexceloffset

Offset VBA Range based upon leftmost cell


I would like to copy all data to the right of a cell and paste it 3 cells to the right of the first selected cell. I am using the following code, but it keeps on jumping 3 columns to the right of the end of the selection.

Range(Selection, Selection.End(xlToRight)).Select
Selection.Cut
Range(ActiveCell.Offset(0, 2)).Select
ActiveSheet.Paste

Is there a way to use the first cell of the selection as the reference for the shift?


Solution

  • Try this (untested):

    Range(Selection, Selection.End(xlToRight)).Select
    Selection.Cut ActiveCell.Offset(0, 2).Select
    ActiveSheet.Paste