0

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

  • Have you tried inserting or deleting cells and shifting lright or left? (.Insert Shift:=xlToRight and .Delete Shift:=xlToLeft in VBA)? – cybernetic.nomad Jan 9 '19 at 18:35
  • Thanks, I'm new to vba and macros I will try and use your suggestion – AustinH Jan 10 '19 at 22:32
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).

| improve this answer | |
0

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

| improve this answer | |

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.