【问题标题】:The information cannot be pasted because the copy area and the paste area are not the same size and shape无法粘贴信息,因为复制区域和粘贴区域的大小和形状不同
【发布时间】:2018-02-01 20:36:53
【问题描述】:

我有一个准备报告的 Excel 宏。该宏每天使用,但今天抛出了上述错误。错误发生在给定代码的最后一行。人们有没有遇到过这个问题? 宏从中提取(并获取错误)的第二个表变得非常大,这会是问题的原因吗?

    Windows("Worldwide_Backlog.xlsm").Activate 'Save File as Worldwide_Backlog'
    Worksheets(3).Activate
        ActiveSheet.PivotTables("PivotTable1").PivotFields("SubFamily2"). _
         ClearAllFilters
        ActiveSheet.PivotTables("PivotTable1").PivotFields("SubFamily2").CurrentPage = _
         "DAS"
        ActiveSheet.PivotTables("PivotTable1").PivotFields("Product Family"). _
          ClearAllFilters
        ActiveSheet.PivotTables("PivotTable1").PivotFields("Product Family"). _
          CurrentPage = "REMI"

    'Clear Filters'

             ActiveSheet.PivotTables("PivotTable1").PivotFields("Age").ClearAllFilters



    'Copy and Paste Table into new Workbook'
              Range("A9").Select
              Selection.End(xlToRight).Select
              Selection.End(xlToLeft).Select
              Range(Selection, Selection.End(xlToRight)).Select
              Range(Selection, Selection.End(xlDown)).Select
              Selection.Copy
              Workbooks.Add
              ActiveSheet.Paste

     'Delete Grand Total from newly pasted table'

         Dim Firstrow As Long
         Dim Lastrow As Long
         Dim Lrow As Long
         Dim CalcMode As Long
         Dim ViewMode As Long

    With Application
         CalcMode = .Calculation
         .Calculation = xlCalculationManual
         .ScreenUpdating = False
    End With


        With ActiveSheet


         .Select


    ViewMode = ActiveWindow.View
    ActiveWindow.View = xlNormalView


    .DisplayPageBreaks = False

    Firstrow = .UsedRange.Cells(1).Row
    Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row


    For Lrow = Lastrow To Firstrow Step -1


        With .Cells(Lrow, "A")

            If Not IsError(.Value) Then

                If .Value = "Grand Total" Then .EntireRow.Delete


            End If

        End With

    Next Lrow

End With

ActiveWindow.View = ViewMode
With Application
    .ScreenUpdating = True
    .Calculation = CalcMode
End With



         Windows("Worldwide_Backlog.xlsm").Activate
         Worksheets(3).Activate
         ActiveSheet.PivotTables("PivotTable1").PivotFields("SubFamily2"). _
         ClearAllFilters
         ActiveSheet.PivotTables("PivotTable1").PivotFields("SubFamily2").CurrentPage = _
         "Ra"
         Range("A11").Select
         Application.CutCopyMode = False

         ActiveSheet.PivotTables("PivotTable1").PivotSelect "Order Number", xlButton, _
         True
         Range(Selection, Selection.End(xlToRight)).Select
         Range(Selection, Selection.End(xlDown)).Select
         Selection.Copy
         Workbooks.Add
         ActiveSheet.Paste




        'Delete Grand Total'

With Application
    CalcMode = .Calculation
    .Calculation = xlCalculationManual
    .ScreenUpdating = False
End With


With ActiveSheet


    .Select


    ViewMode = ActiveWindow.View
    ActiveWindow.View = xlNormalView


    .DisplayPageBreaks = False


    Firstrow = .UsedRange.Cells(1).Row
    Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row


    For Lrow = Lastrow To Firstrow Step -1


        With .Cells(Lrow, "A")

            If Not IsError(.Value) Then

                If .Value = "Grand Total" Then .EntireRow.Delete


            End If

        End With

    Next Lrow

End With

ActiveWindow.View = ViewMode
With Application
    .ScreenUpdating = True
    .Calculation = CalcMode
End With


          Range("M1").Select
             ActiveCell.FormulaR1C1 = "Vlookup"
             Range("M2").Select
             ActiveCell.FormulaR1C1 = "=VLOOKUP(C[-12],[Book1]Sheet1!C1,1,0)"
             Range("L2").Select 'AutoFills'
                Selection.End(xlDown).Select
                ActiveCell.Offset(0, 1).Select
                Range(Selection, Selection.End(xlUp)).Select
                Selection.FillDown


             Columns("M:M").Select
             Selection.AutoFilter
             ActiveSheet.Range("$M$1:$M$21").AutoFilter Field:=1, Criteria1:="=#N/A", _
             Operator:=xlOr, Criteria2:="="
             Range("A2").Select
             Range(Selection, Selection.End(xlToRight)).Select
             Range(Selection, Selection.End(xlDown)).Select
             Selection.Copy
             Windows("Book1").Activate
             ActiveSheet.Range("A" & Rows.Count).End(xlUp).Offset(1).Select 'Uses first blank cell'
             ActiveSheet.Paste

【问题讨论】:

  • 确保粘贴前的选择实际上选择了一个单元格。在此选择之后设置断点,然后检查工作表;选择将可见。

标签: vba excel


【解决方案1】:

工作表数据格式错误。 工作表中有一些行将一些列合并为一个,从而减少了这些行的列数。 这就是它抱怨尺寸差异的原因。

将数据复制到notepad++并检查格式问题。

【讨论】:

    【解决方案2】:

    目标文件处于兼容模式。 转到文件>信息转换>保存。 这将解决您的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-19
      • 1970-01-01
      相关资源
      最近更新 更多