簡體   English   中英

錯誤1004:Excel VBA

[英]Error 1004: Excel VBA

錯誤發生在ActiveSheet.Cells(q,1).Offset(2,1).PasteSpecial.xlPasteValues

想知道為什么我會遇到運行時錯誤1004。它提到無法粘貼信息,因為復制區域和粘貼區域的大小和形狀不相同。 有沒有解決的辦法?

                     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