[英]how to paste entire column in excel vba without selecting the sheet
I'm trying to copy the first column into the last column.我正在尝试将第一列复制到最后一列。 What's wrong with this code?这段代码有什么问题? Getting the following error:得到以下错误:
Run-time error '438
object doesn't support this property or method
Does vba allow Copy
but not paste
for columns? vba 是否允许对列进行Copy
但不允许paste
?
Sub copy_ids_user_output(sheet_name As String)
' find last column
Dim last_col As Integer
last_col = Worksheets(sheet_name).Cells(1, Columns.Count).End(xlToLeft).column
Debug.Print last_col
Columns(1).Copy
Columns(last_col + 1).Paste
End Sub
If possible, you should avoid clobbering the user's clipboard in a macro.如果可能,您应该避免在宏中破坏用户的剪贴板。 Just copy the column directly.直接复制列即可。
Columns(1).Copy Columns(last_col + 1)
You should select destination and then use paste:您应该选择目的地,然后使用粘贴:
instead of:代替:
Columns(last_col + 1).Paste
use用
Columns(last_col + 1).Select
ActiveSheet.Paste
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.