I know this is kind of a common topic but I'm having trouble finding the best solution.
I'm simply trying to move a group of five rows (say Range("11:15") ) to another location ( Range("6:10") ) without over writing the location ( shift:=xlDown ). I can do this just fine with the code below. But I would like to do this without using the copy/paste clipboard. I've tried several ways, but they result in errors or unwanted results. Any suggestions?
This does the job (but uses clipboard):
RngSel.Cut RngSel.Offset(AtvEnd * 5).Insert shift:=xlDown
Thanks for any help!
Last edited by treyr; 06-22-2010 at 11:19 AM.
Hi there,
why do you want to do this without using the clipboard?
J.
Hello Jevni,
I was looking to avoid interfering with the user's clipboard. If something were stored on it, and this code ran, it would clear the user's info just so I could just move some cells. I figured there always seems to be a better way to directly reference the excel object model rather than resorting to the clipboard or selections.
For example, I do not use .Select, as generated by the "Recorder", to write info to cells:
I would use:Range("C4").Select ActiveCell.FormulaR1C1 = "Hello World" Range("C5").Select
Range("C12").Value = "Hello World"
Or not use copy/paste to copy info
I would use:Range("C5").Select Selection.Copy Range("C8").Select ActiveSheet.Paste
Range("C8").Value = Range("C5").Value
I was hoping there was a way to move one range to the location of another range of the same size. Something like:
This works without the "Shift:=xlDown", but certainly not with it.MyRange1.cut Destination:=MyRange2 Shift:=xlDown
It's not a critical thing for my code to live without, I just thought there was a more "proper" way to move info around the object model than using the clipboard.
If you cut or copy, it's going to the clipboard -- both clipboards. You can clear the Excel clipboard when you're done, following a Copy:
Application.CutCopyMode = False
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
That's defiantly something I should use to clean up with after I'm done, thanks shg and jevni.
But I suppose there is no real way to move rows around without the use of the clipboard? I suppose even when I set the CutCopyMode to False, it still killed what was on the clipboard from before the code ran?
No big deal:
sub tst() sheets(1).rows(6).resize(5).insert sheets(1).rows(6).resize(5)=sheets(1).rows(16).resize(5).value sheets(1).rows(16).resize(5).delete End Sub
Wow,
Very cool, I'll use that! Thanks for the help!
Be aware that the formulas referring to the original cells will have #REF errors, and formulas will be replaced by values.
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
Ah, I'll make to sure to be cognizant of references to those cells. This problem would also exist if I use the copy/cut method correct?
For the cell's formulas, the below code seems to work
I think this is the more solid type of code I was looking for.sheets(1).rows(6).resize(5)=sheets(1).rows(16).resize(5).Formula
Mucho thanks yall!
If you copy, yes. If you cut, no.This problem would also exist if I use the copy/cut method correct?
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks