复制粘贴定义的单元格时出现“运行时错误'1004”

时间:2019-08-14 09:02:49

标签: excel vba ms-error-1004

我有一个宏,用于在工作簿之间复制和粘贴单元格。在线SouceWorksheet.Range(“ B72:B94”)。Copy TargetWorksheet.Range(“ B72:B94”)我收到运行时错误1004。在此范围内,单元格未合并。当我更改B95的范围并粘贴到B95时,一切都可以...... p

For Each SouceWorksheet In oWB.Worksheets
        On Error Resume Next
        Set TargetWorksheet = ThisWorkbook.Worksheets(SouceWorksheet.Name)
        On Error GoTo 0

        If TargetWorksheet.Name <> "aaa" Or TargetWorksheet.Name <> "x" And TargetWorksheet.Name <> "y" And TargetWorksheet.Name <> "z" Then


        SouceWorksheet.Range("C7").Copy TargetWorksheet.Range("C7")
        SouceWorksheet.Range("H8").Copy TargetWorksheet.Range("H8")

        TargetWorksheet.Range("C9").UnMerge
        SouceWorksheet.Range("C9").Copy TargetWorksheet.Range("C9")
        TargetWorksheet.Range("C9:D9").Merge
        Application.DisplayAlerts = False

        TargetWorksheet.Range("C10").UnMerge
        SouceWorksheet.Range("C10").Copy TargetWorksheet.Range("C10")
        TargetWorksheet.Range("C10:D10").Merge
        Application.DisplayAlerts = False

        SouceWorksheet.Range("L10:M10").Copy TargetWorksheet.Range("L10:M10")

            If SouceWorksheet.Range("C12") = "V1" Then
                SouceWorksheet.Range("C12").Copy TargetWorksheet.Range("C12")
                SouceWorksheet.Range("C14").Copy TargetWorksheet.Range("C14")
                SouceWorksheet.Range("F14:F15").Copy TargetWorksheet.Range("F14:F15")
            Else
                SouceWorksheet.Range("C12").Copy TargetWorksheet.Range("C12")
                SouceWorksheet.Range("F18:F20").Copy TargetWorksheet.Range("F18:F20")
            End If

        SouceWorksheet.Range("L14:L15").Copy TargetWorksheet.Range("L14:L15")

        SouceWorksheet.Range("C24:C26").Copy TargetWorksheet.Range("C24:C26")

        SouceWorksheet.Range("C28:D29").Copy TargetWorksheet.Range("C28:D29")

        SouceWorksheet.Range("C34:E36").Copy TargetWorksheet.Range("C34:E36")

        SouceWorksheet.Range("C40:E42").Copy TargetWorksheet.Range("C40:E42")

        SouceWorksheet.Range("C45:C46").Copy TargetWorksheet.Range("C45:C46")

        SouceWorksheet.Range("C49").Copy TargetWorksheet.Range("C49")

        SouceWorksheet.Range("F45:G49").Copy TargetWorksheet.Range("F45:G49")

        SouceWorksheet.Range("H45:I49").Copy TargetWorksheet.Range("H45:I49")

        SouceWorksheet.Range("C53:C54").Copy TargetWorksheet.Range("C53:C54")

        TargetWorksheet.Range("C65").UnMerge
        SouceWorksheet.Range("C65").Copy TargetWorksheet.Range("C65")
        TargetWorksheet.Range("C65:D66").Merge
        Application.DisplayAlerts = False

        SouceWorksheet.Range("B72:B94").Copy TargetWorksheet.Range("B72:B94")

        SouceWorksheet.Range("J72:J94").Copy TargetWorksheet.Range("J72:J94")


        End If
    Next

        For Each ws In ThisWorkbook.Worksheets
        ws.Calculate
        Next ws

    oWB.Close False

请帮助:)

0 个答案:

没有答案