问题
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