简体   繁体   English

错误1004:Excel VBA

[英]Error 1004: Excel VBA

The error occurs at ActiveSheet.Cells(q,1).Offset(2,1).PasteSpecial.xlPasteValues 错误发生在ActiveSheet.Cells(q,1).Offset(2,1).PasteSpecial.xlPasteValues

Was wondering why I am faced with a runtime error 1004. It mentions that the information cannot be pasted as copy area and paste area are not the same size and shape. 想知道为什么我会遇到运行时错误1004。它提到无法粘贴信息,因为复制区域和粘贴区域的大小和形状不相同。 Is there a work around? 有没有解决的办法?

                     For i = 1 To testrows
                            For j = 1 To testcols

                                If (range1.Cells(i, j).Value <> range2.Cells(i, j).Value) Then
                                     'Conclude that range dimension is not the same
                                     bMatches = False
                                     i = testrows
                                     j = testcols
                                     'Exit loops
                                End If
                            Next
                        Next
                    End If

                    'If ranges of two comparison sheets are the same
                    If bMatches Then
                        rowmatched = True
                        k = referencesheetcols
                    End If

                    'Sheets(outputsheetname).Cells(1, 1).Value = rowmatched
                    'Set place to paste data
                    If (Not (rowmatched) And k = referencesheetcols) Then
                        range2.Copy
                        Sheets(referencesheetname).Cells(p, 1).Offset(2, 0).Select
                        ActiveSheet.Paste
                        p = p + 1
                        Sheets("Datasheet").Activate
                        'ActiveSheet.Cells(q, 1).Offset(2, 1).Select
                        ActiveSheet.Cells(q, 1).Offset(2, 1).PasteSpecial xlPasteValues
                        'ActiveSheet.PasteSpecial xlPasteValues
                        q = q + 1
                    End If
                    Next
            End If
        Next

    End Sub`enter code here`
'.....
If (Not (rowmatched) And k = referencesheetcols) Then

    range2.Copy Sheets(referencesheetname).Cells(p, 1).Offset(2, 0)
    p = p + 1

    Sheets("Datasheet").Cells(q, 1).Offset(2, 1).Resize( _
        range2.Rows.Count, range2.Columns.Count).Value = range2.Value
    q = q + 1

End If
'.....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM