VBA Copy and Paste Method Not Working

2019-07-20 03:22发布

I am trying to write a simple copy and paste macro and it works up until the last line. When it hits the last line, it says the paste function will not work. I am really confused why this is happening and any help on this would be greatly appreciated.

Sheet2.Columns("A:B").Insert Shift:=xlToRight
Sheet2.Columns("F:G").Cut
Sheet2.Activate
Columns("A:B").Select
ActiveSheet.Paste
Sheets("SourceData").Columns("A:B").Insert Shift:=xlToRight
Sheets("SourceData").Activate
Columns("A:B").Select
ActiveSheet.Paste                   <-LINE THAT THROWS ERROR

My error message is Paste Method of Worksheet Class failed

2条回答
Ridiculous、
2楼-- · 2019-07-20 03:56

you need a second cut (or copy) command to go with your second Activesheet.Paste command

查看更多
Deceive 欺骗
3楼-- · 2019-07-20 04:01

You are receiving the error because you have already emptied the clipboard with the first "cut/paste" operation.

Try this instead:

Sheet2.Columns("A:B").Insert Shift:=xlToRight
Sheet2.Columns("F:G").Cut
Sheet2.Activate
Columns("A:B").Select
ActiveSheet.Paste
Activesheet.Columns("A:B").Copy

Sheets("SourceData").Columns("A:B").Insert Shift:=xlToRight
Sheets("SourceData").Activate
Columns("A:B").Select
ActiveSheet.Paste   
查看更多
登录 后发表回答