VBA Copy and Paste Method Not Working

只谈情不闲聊 提交于 2020-01-24 12:41:48

问题


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


回答1:


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




回答2:


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   


来源:https://stackoverflow.com/questions/26065376/vba-copy-and-paste-method-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!