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)
- I can't use copy and paste as it duplicated the data
- 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
3 Answers
Is Paste Special what you're looking for? This is what the Paste dropdown looks like in Excel 2007:
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).
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 FunctionModule2
Sub Endshifter() Application.OnKey "{LEFT}" Application.OnKey "{RIGHT}"
End Sub 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.