Object Missing?

jski21

Board Regular
Joined
Jan 2, 2019
Messages
133
Office Version
  1. 2016
Platform
  1. Windows
Good day Mr. Excel Team,

Here's a snippet of code I'm using. Essentially trying to copy a pivot table and paste special the values in:

With ActiveSheet.PivotTables("DrawData").PivotFields("Years")
.Orientation = xlRowField
.Position = 2
Range("A6:F6").Select
Selection.Font.Size = 11
Range("A7").Select
ActiveSheet.PivotTables("DrawData").PivotSelect "Grant[All]", xlLabelOnly + _
xlFirstRow, True
Selection.Font.Size = 11
ActiveSheet.PivotTables("DrawData").PivotSelect "", xlDataAndLabel, True
Selection.Copy

Range("A35").Select.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False


Application.CutCopyMode = False

End With

Getting an Object required error on the isolated red highlighted text portion above. What am I missing? (Object obviously, but need a bit of a nudge on this). Thanks.


jski
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Maybe more like
VBA Code:
Range("A35").Select
Selection.PasteSpecial....
or
VBA Code:
With Range("A35")
  .Select
  .PasteSpecial...
as PasteSpecial is a method of a Range object and you haven't provided a range to paste into. Maybe see
In fact, I have the root of the Office object model as a bookmark
 
Upvote 0
Thanks Micron. Still having a bit of trouble with this. Boiled it down to the following:

'***Copy Pivot table
ActiveSheet.PivotTables("DrawData").PivotSelect "", xlDataAndLabel, True
Selection.Copy


'***PasteSpecial Values of Pivot table
Range("A35").PasteSpecial Operation:=xlPasteSpecialOperationPasteFormats, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False


The copy statement works fine. The PasteSpecial statement now gives me a "PasteSpecial method of Range class failed" error.

I'm certain I'm missing something rather minor but can't determine what.


Thanks.
 
Upvote 0
The copy statement works fine.
If that means it doesn't error, it's not the same thing as "it works". Perhaps you copied nothing? Put a break point on the paste line, open a new text document and ctrl+V in it. If you paste nothing, you didn't copy anything, which will raise that error AFAIK.
Don't you need to provide a name for the PivotSelect method?
I've also read that you can't initiate this from the macro dialog as your selection will be lost, so how are you running the code?
 
Last edited:
Upvote 0
It should be Paste:=xlPasteSpecialOperationPasteFormats not Operation:=xlPasteSpecialOperationPasteFormats
 
Upvote 0
Thanks gentlemen. Micron--I put the break in and the copy statement did work. The code presented initially is extracted from a longer sub, used to modify an unfriendly excel downloaded from a reporting platform. Rory--tried that line of code and received the same error message. I fiddled a bit and got this to work:

'***Copy Pivot table
ActiveSheet.PivotTables("DrawData").PivotSelect "", xlDataAndLabel, True
Selection.Copy

'***PasteSpecial Values of Pivot table
Range("A35").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Would not have been able to solve this without each of your comments and guidance. Thanks!

jski
 
Upvote 0
Solution

Forum statistics

Threads
1,214,787
Messages
6,121,565
Members
449,038
Latest member
Guest1337

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