My code is as follows. I have Rng set as a range in my looping macro, and this is a sub of that. If a certain condition is met, then the following sub is called:
Sub FKCutandPaste(Rng As Range)
Rng.Resize(, 9).Cut
Rng.Offset(, 19).Insert Shift:=xlDown
Rng.Resize(, 9).Delete Shift:=xlUp
I want this to cut out a section of the data, then paste it away from the active columns. However, the macro seems to just cut out the the required cells, but doesn’t move onto the second line.
Am I missing something very small here?
I can’t tell you if you have any specific problem. This code works fine for me, with an arbitrary sheet with data (and as its own sub), in Excel 2010:
I added the ‘select’ bit because that’s often helpful in testing – put a break on the select, run to it, then F8 the line; then see what’s selected. If it errors right there, then there’s something wrong with rng.offset(,19). If it succeeds and selects (something), then you can see where it thinks it should be inserting the data.
Edit: Commenting out the rng.Resize(,9).Delete seems to fix the problem – it’s deleting the newly inserted cells. When you use rng.cut, and then paste the cells in, that seems to change the current location of rng. See this:
Change ‘cut’ to ‘copy’ and the behavior changes. You may want to simply do that – change it to copy – as you delete the original cells anyway.