1

Hi I would like to know how to run a VBA or macro (or any other simpler way) to shift the values only of any current selection (varying from one cell in one row to multiple cells and selections across rows, columns) in excel to the right one column or left one column.

In short, I am preparing a forecast sheet for an architecture practice. It works in the same way as Microsoft project with rows of timelines shown over a number of monthly columns. when a project timeline shifts I need to be able to select a row of data, single or multiple cells and move the selected data only over by one column. It would be great to remove the data from the previous cell location also (cut and paste data only in essence)

  1. I can't use copy and paste as it duplicated the data
  2. select and drag on the edge of bounding box with the four star cursor takes the formulas, connections and formatting

See photo attached - imagine the two 50% allocations in Apr-19 and May-19 need to push out to begin in July. Simply, I want to select those cells and shift the data only - as if using the right arrow key (or left arrow key) to move the data only like tetris.

Look forwarding to hear your suggestions
enter image description here

2
  • Have you tried inserting or deleting cells and shifting lright or left? (.Insert Shift:=xlToRight and .Delete Shift:=xlToLeft in VBA)? Commented Jan 9, 2019 at 18:35
  • Thanks, I'm new to vba and macros I will try and use your suggestion
    – AustinH
    Commented Jan 10, 2019 at 22:32

4 Answers 4

1

Here is an answer, although I think it will cause you more pain than pleasure. Using cut and paste with ctrl+x and ctrl+v will probably save many headaches.

Make two modules in your workbook. Add the code below. Run module1 to activate the key swap, and Run module2 to turn it off. While on, your right and left arrow keys will shift your data right or left and destroy data in the old cell. Formulas will be removed. USE WITH CAUTION.

I recommend making buttons to activate these two modules.

Module1

Sub shifter()
    Application.OnKey "{LEFT}", "LShift"
    Application.OnKey "{RIGHT}", "RShift"

End Sub

Function LShift()
    Selection.Offset(0, -1).Value2 = Selection.Value2
    Selection.Value2 = ""
    Selection.Offset(0, -1).Select

End Function

Function RShift()
    Selection.Offset(0, 1).Value2 = Selection.Value2
    Selection.Value2 = ""
    Selection.Offset(0, 1).Select
End Function

Module2

Sub Endshifter()
    Application.OnKey "{LEFT}"
    Application.OnKey "{RIGHT}"

End Sub

0

Is Paste Special what you're looking for? This is what the Paste dropdown looks like in Excel 2007:

enter image description here

It's not clear to me why a simple cut and paste won't work for you (maybe that it will carry the cell highlighting/formatting? But you didn't really say that was your issue), so I'm not certain this will solve your problem, but it offers a number of options to refine your paste. Note that if you don't want to duplicate data, use cut (Ctrl+X) instead of copy (Ctrl+C).

0

If I'm understanding the question correctly, you can use the Paste As Formula function instead of a normal paste. After you Cut & Paste, hit Ctrl, F, Enter. You can also assign a custom shortcut, but the preceding method should work out-of-box.

0

You shouldn't have been using Cut and Paste to begin with, if I'm understanding your question correctly. Instead, you should be using Cut and Insert Copied Cells via Ctrl+X, Context Menu</kbd, E. This will move the cells to your current cursor position (above and/or to the left) and shift cells according to your selection; you can also do this with rows/columns. This also retains the correct calculation values for all other cells affected by the change (assuming they have relative references or absolute references); if you don't want the automated effect, use Indirect().

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .