Excel 复制参数不适用于范围对象
我试图复制一个表并将其粘贴到工作表的其他位置(用户选择的目标单元格): 但是我在Excel 复制参数不适用于范围对象,excel,vba,Excel,Vba,我试图复制一个表并将其粘贴到工作表的其他位置(用户选择的目标单元格): 但是我在表上得到一个错误。复制部分: 参数数目错误或属性赋值无效 Sub-PasteMacro() 变暗目标 我想我会坚持多久 调暗表作为范围 双倍重量 双厚度 阴沉僵硬 Set shA=ActiveWorkbook.Worksheets(“用户工作表comp数据”) '搜索表中第一个非0对齐 i=19 直到范围(“M”和“i”)0 i=i-1 环 MsgBox单元(i,13).地址 “要复制的表 集合表格=shA.范围(
表上得到一个错误。复制部分:
参数数目错误或属性赋值无效
Sub-PasteMacro()
变暗目标
我想我会坚持多久
调暗表作为范围
双倍重量
双厚度
阴沉僵硬
Set shA=ActiveWorkbook.Worksheets(“用户工作表comp数据”)
'搜索表中第一个非0对齐
i=19
直到范围(“M”和“i”)0
i=i-1
环
MsgBox单元(i,13).地址
“要复制的表
集合表格=shA.范围(单元格(1,2),单元格(i,15))
重量=沙粒范围(“O20”)
厚度=沙的范围(“M20”)
刚性=沙范围(“M21”)
出错时继续下一步
'要求用户选择要粘贴表格的单元格
设置target=Application.InputBox(提示:=“请选择要在其中显示的目标单元格。”
“粘贴”,类型:=8)
错误转到0
如果不是answ,那就什么都不是了
'复制表格并粘贴它
表。复制,shA.target
如果结束
端接头
应该是
:
自:
Destination
参数是Copy()
方法的第一个参数,而分隔后续(如果有)参数则需要逗号
target
是一个范围
对象,因此它已经完全符合其父工作表和工作簿对象的条件
此外,我想
If Not answ Is Nothing Then
应该是
:
这是修改后的代码
Sub PasteMacro()
Dim target As Range
Dim table As Range
Dim i As Long
Dim weight As Double
Dim thickness As Double
Dim Stiff As Double
Dim shA As Worksheet
With ActiveWorkbook.Worksheets("User sheet comp data")
' search for the first non 0 ligne in the table
i = 19
Do Until .Range("M" & i) <> 0
i = i - 1
Loop
MsgBox .Cells(i, 13).Address
'the table to copy
Set table = .Range(Cells(1, 2), Cells(i, 15))
weight = .Range("O20").Value2
thickness = .Range("M20").Value2
Stiff = .Range("M21").Value2
On Error Resume Next
Set target = Application.InputBox(Prompt:="Please select a destination Cell where you want to Paste ", Type:=8)
On Error GoTo 0
If Not target Is Nothing Then table.Copy target 'copy the table and paste it
End With
End Sub
Sub-PasteMacro()
作为射程的弱小目标
调暗表作为范围
我想我会坚持多久
双倍重量
双厚度
阴沉僵硬
Dim shA作为工作表
使用ActiveWorkbook.worksheet(“用户工作表组件数据”)
'搜索表中的第一个非0对齐
i=19
直到.Range(“M”和i)0为止
i=i-1
环
MsgBox.Cells(i,13).地址
“要复制的表
集合表格=.Range(单元格(1,2),单元格(i,15))
重量=.范围(“O20”).值2
厚度=.范围(“M20”).值2
刚性=.范围(“M21”).值2
出错时继续下一步
设置目标=应用程序.InputBox(提示:=“请选择要粘贴的目标单元格”,类型:=8)
错误转到0
如果不是目标,则表为空。复制目标复制表并粘贴它
以
端接头
正如您所看到的,所有范围对象(范围、单元格)都在引用ActiveWorkbook.worksheet(“用户工作表comp数据”)
(“MilestoneDueDate”)
通过他们前面的点(.)
这样你就不会失去对在哪张表格中考虑的范围的控制
table.Copy target
If Not answ Is Nothing Then
If Not Target Is Nothing Then
Sub PasteMacro()
Dim target As Range
Dim table As Range
Dim i As Long
Dim weight As Double
Dim thickness As Double
Dim Stiff As Double
Dim shA As Worksheet
With ActiveWorkbook.Worksheets("User sheet comp data")
' search for the first non 0 ligne in the table
i = 19
Do Until .Range("M" & i) <> 0
i = i - 1
Loop
MsgBox .Cells(i, 13).Address
'the table to copy
Set table = .Range(Cells(1, 2), Cells(i, 15))
weight = .Range("O20").Value2
thickness = .Range("M20").Value2
Stiff = .Range("M21").Value2
On Error Resume Next
Set target = Application.InputBox(Prompt:="Please select a destination Cell where you want to Paste ", Type:=8)
On Error GoTo 0
If Not target Is Nothing Then table.Copy target 'copy the table and paste it
End With
End Sub