Error cutting and pasting VBA

I try to cut out the contents of cell K7 (100) and paste it into M7 using VBA (see below), but I keep getting an error (see below). Where am I going wrong ?:

Sub CutPaste() Worksheets("Sheet2Test").Activate Range("K7").Select Selection.Cut Range("M7").Select Selection.Paste End Sub 

enter image description here

enter image description here

+4
source share
2 answers

Better to avoid Select at all. Use it

 Worksheets("Sheet2Test").Range("K7").Cut Worksheets("Sheet2Test").Range("M7") 
+9
source

Just replace Selection.Paste with ActiveSheet.Paste so that it will be:

 Sub CutPaste() Worksheets("Sheet2Test").Activate Range("K7").Select Selection.Cut Range("M7").Select ActiveSheet.Paste End Sub 

This will make the paste the way you like.

+6
source

Source: https://habr.com/ru/post/1445226/


All Articles