简体   繁体   中英

There is an Error 1004: Application defined or object defined error

Hi guys I am currently recording in a macro. I am turning raw datas in pivot table and automate it using macro. But whenever I press the button there is an error 1004: Application-defined or object-defined error.

Here are the sample of my codes in the VBA.

ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
    "'Sheet1!R4C1:R279594C33'", Version:=xlPivotTableVersion14).CreatePivotTable _
    TableDestination:="'Sheet8!R3C1'", TableName:="'PivotTable3'", DefaultVersion _
    :=xlPivotTableVersion14

I hope you could assist me guys on this one.

Thank you very much.

You got the apostrophes in your SourceData and the TableDestination incorrect. The apostrophes should be only around the sheet name and not including the rows / columns towards the end. So, you got this:

"'Sheet1!R4C1:R279594C33'"

while it should be this

"'Sheet1'!R4C1:R279594C33"

The same applies to the TableDestination which should be "'Sheet8'!R3C1" .

Also, note that this code can only work once! This is due to the fact that you name the newly created PivotCache "PivotTable3". As there can be only one PivotCache by that name the second run of the above code will automatically fail (unless you delete the "PivotTable3" before running the above code).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM