PasteSpecial method of Range class failed

azizrasul

Well-known Member
Joined
Jul 7, 2003
Messages
1,304
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
I get the error 'PasteSpecial method of Range class failed' on line

Code:
.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

in the code below.

Essentially I'm creating a pivot table in Sheet2 whose results I want to transfer to another sheet. The code is being run from a label on a sheet called 'Dashboard'.

Code:
    Sheets("Sheet1").Range("A1:D" & Sheets("Sheet1").UsedRange.Rows.Count).Select
    Sheets.Add
    Sheets(Sheets.Count - 1).Name = "Sheet2"
    
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:="Sheet1!R1C1:R" & Sheets("Sheet1").UsedRange.Rows.Count & "C4", Version:=xlPivotTableVersion12).CreatePivotTable TableDestination:="Sheet2!R3C1", TableName:="PivotTable3", DefaultVersion:=xlPivotTableVersion12
    
    With Sheets("Sheet2")
        With .Cells(3, 1)
            ActiveWorkbook.ShowPivotTableFieldList = True
        End With
    End With
    
    With ActiveSheet.PivotTables("PivotTable3").PivotFields("Location")
        .Orientation = xlRowField
        .Position = 1
    End With
    
    ActiveSheet.PivotTables("PivotTable3").AddDataField ActiveSheet.PivotTables("PivotTable3").PivotFields("Star Rating"), "Sum of Star Rating", xlSum
    Debug.Print Sheets("Sheet2").UsedRange.Rows.Count
    Sheets("Sheet2").Range("A4:A" & Sheets("Sheet2").UsedRange.Rows.Count + 1).Copy
    
    With Sheets("DETAILED - KPI 5")
        With .Range("B130:I200")
            .ClearContents
        End With
        With .Range("B130")
            .PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        End With
    End With
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
I don't think anything is actually available to copy.

That's because of the ClearContents code between the copy and paste.
 
Upvote 0

Forum statistics

Threads
1,224,594
Messages
6,179,792
Members
452,942
Latest member
VijayNewtoExcel

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top