【发布时间】:2015-02-10 04:36:12
【问题描述】:
我正在尝试创建一个可能最终会变得非常大的 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'
谁能建议我哪里出错了?
【问题讨论】:
-
您尝试记录过程吗? Record 宏功能通常会提示您出错的地方。尝试复制一些内容并将其粘贴到其他地方,同时记录和研究该代码。