79725103

Date: 2025-08-04 15:29:07
Score: 0.5
Natty:
Report link

Adjusting the code a bit, I discovered that, as I suspected, the error comes from PivotCaches.Create. What answered my question was changing the PivotCaches.Create inside my For Each loop.

For Each ws In wbAnualizacao.Worksheets
    If ws.Name <> "Dados" Then
        tabelaExiste = False
        
    Set pc = wbAnualizacao.PivotCaches.Create( _
        SourceType:=xlDatabase, _
        SourceData:=rangeDados)

Creating a PivotCache in a For Each is probably not a pretty thing, and on larger scales, it can create more problems. But due to the lack of information online, it was the best I could come up with.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: JvSitta