如何在循环更改时更改范围 - 运行时错误"1004":应用程序定义或对象定义错误



我正在尝试浏览工作表(粘贴此处(并将名称与工作表(分解(匹配。当两个名称匹配时,我需要从工作表中复制区域(粘贴到此处(并粘贴到工作表中(分解(。由于某种原因,我遇到了一个运行时错误,不允许我使用当前范围进行复制和粘贴。

Sub Stats()
Dim Row As Integer
Dim RowP As Integer
Dim Col As Integer
For Row = 2 To 200
For RowP = 2 To 200
If Worksheets("PasteHere").Cells(RowP, 2) = Worksheets("Breakdown").Cells(Row, 2) Then 
Worksheets("PasteHere").Range("IRowP:CRRowP").Copy Worksheets("Breakdown").Range("IRow:CRRow")
End If    
Next RowP
Next Row
MsgBox "Done"
End Sub

Dim Row As Integer
Dim RowP As Integer
Dim Col As Integer
For Row = 2 To 200
For RowP = 2 To 200
If Worksheets("PasteHere").Cells(RowP, 2) = Worksheets("Breakdown").Cells(Row, 2) Then 
Worksheets("PasteHere").Range("I" & RowP & ":CR" & RowP).Copy Worksheets("Breakdown").Range("I" & Row & ":CR" & Row)
End If    
Next RowP
Next Row
MsgBox "Done"
End Sub

当您使用Row和RowP变量时,您必须跳出双引号vba字符串并使用&要连接的字符。

相关内容

最新更新