我正在尝试创建一个可能最终变得相当大的excel宏,以使事情变得更容易我正在一次处理它。到目前为止,我有....Excel宏在粘贴时给出错误
Sub Macro4()
'
' Test Macro
'
'Selects the product_name column by header name
Dim rngAddress As Range
Set rngAddress = Range("A1:Z1").Find("product_name")
If rngAddress Is Nothing Then
MsgBox "The product_name column was not found."
Exit Sub
End If
Range(rngAddress, rngAddress.End(xlDown)).Select
'Inserts new column to the left of the product_name column
Selection.Insert Shift:=xlToRight
'Re-selects the product_name column
Range(rngAddress, rngAddress.End(xlDown)).Select
'Copys the contents of the product_name column
Selection.Copy
Selection.Paste
End Sub
我想要它做以下....
- 搜索电子表格的标题名称“PRODUCT_NAME”
- 将空白列到“PRODUCT_NAME”列
- 复制“PRODUCT_NAME”列的内容的左边
- 它们粘贴到新创建的空白列
- 更改标题名称在这个新列“PRODUCT_NAME_2”
目前,它工作得很好,直到粘贴到这个新创建的列,然后我得到一个
'Run-time error '438'; - Object doesn't support this property or method'
任何人都可以提出我要去哪里错了吗?
您是否尝试记录过程?记录宏函数通常会提示您出错的地方。尝试复制某些东西并粘贴到其他地方,同时记录并研究该代码。 – Default 2012-01-02 15:15:06