So you’ve got a file with dozens of PivotTables in it. One day you hit Refresh All, only to see this complaint:
…or perhaps this variant:
What’s happened is that the size of the PivotTable has increased, and the PivotTable is now trying to occupy space where another Pivot or Excel Table already lives. So you know what has gone wrong. But you have no idea where. You’re either going to need to eyeball each and every bit of each and every worksheet (including the hidden ones), or you’re going to have to run a bit of code. Something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
Sub FindPivotOverlaps() Dim ws As Worksheet Dim pt As PivotTable Dim pt2 As PivotTable Dim lo As ListObject Dim rOffset As Range Dim cell As Range Dim sMsg As String For Each ws In ActiveWorkbook.Worksheets For Each pt In ws.PivotTables With pt.TableRange2 Set rOffset = Union( _ .Offset(pt.TableRange2.Rows.Count, 0).Resize(1), _ .Offset(0, pt.TableRange2.Columns.Count).Resize(pt.TableRange2.Rows.Count, 1)) End With 'Test for ListObject collision Set lo = Nothing On Error Resume Next Set lo = rOffset.ListObject On Error GoTo 0 If Not lo Is Nothing Then sMsg = sMsg & lo.Name & vbTab & "'" & lo.Parent.Name & "'!" & lo.DataBodyRange.Address & vbNewLine Else 'Test for PivotTable collision For Each cell In rOffset Set pt2 = Nothing On Error Resume Next Set pt2 = cell.PivotTable On Error GoTo 0 If Not pt2 Is Nothing Then sMsg = sMsg & pt2.Name & vbTab & "'" & pt2.Parent.Name & "'!" & pt2.TableRange2.Address & vbNewLine Exit For End If Next cell End If Next pt Next ws If sMsg = "" Then sMsg = "No overlaps found!" MsgBox sMsg End Sub |
…which does this:
Thanks! I’m still having some issues when refreshing pivots that come from olap sources (when changing the data source options), but this works for most of the other cases!
Best regards
Hi Martin. Can you elaborate further about the nature of the issues?
Sub M_snb()
For Each it In Sheets
ReDim sn(it.ListObjects.Count + it.PivotTables.Count - 1)
If UBound(sn) > -1 Then
sn(0) = IIf(it.ListObjects.Count > 0, it.ListObjects(1).Range.Address, it.PivotTables(1).TableRange2.Address)
For j = 2 To UBound(sn) + 1
If j it.ListObjects.Count Then Set c00 = it.PivotTables(j - it.ListObjects.Count).TableRange2
For jj = 0 To UBound(sn)
If IsEmpty(sn(jj)) Then Exit For
If Not Intersect(Range(sn(jj)), c00) Is Nothing Then Exit For
Next
If IsEmpty(sn(jj)) Then
sn(jj) = c00.Address
ElseIf jj <= UBound(sn) Then
MsgBox "Overlap " & sn(jj) & vbTab & c00.Name, , it.Name
Exit Sub
End If
Next
MsgBox Join(sn, vbLf), , it.Name & " no overlap"
End If
Next
End Sub
Truly a life saver. Thx a lot!
Thank you, this was really a life saver.
can you teach me how to run the code? step by step.
Thanks in advanced.
Hi Evelyn. I wrote a blog post some time back over at the Chandoo blog that has step-by-step instructions. See https://chandoo.org/wp/using-personal-macro-workbook/
Identifying PivotTable Collisions
Posted on December 8, 2017 by Jeff Weir
I copyed code and it works! Said “No overlaping found”! I was happy, but when I refreshed my pivots, I got a same massage “Pivot can’t overlap another pivot…”.
I also checked manualy all my 50 sheets – and there is no overlaping, but after transition to office 365, I keep goting this error on refresh.
What to do?
SNB?
snb reports sintax error in my vb editor
Mirko…can you share you file with me so I can take a look? If lo, let me know and I’ll email you directly.
I have a file that has a bunch of pivot tables. When I hit Refresh All I get the overlap error plus an additional error “A PivotTable, cube function or filter control using connection ‘Connection 321’ didn’t refresh. Continue to refresh all?” which causes none of the pivot tables to refresh at all. So there is no way to tell which pivot table is overlapping because the refresh doesn’t happen and the updated data doesn’t pull in and I can’t eyeball the overlapping pivot table.
Is there a fix to this?
The code plugged-in easy and worked PERFECTLY the first time! Thank you Jeff! You saved the day. :)
Thank you so much Jeff – I’m afraid I also have the issue of getting the overlap error in Office 365, but no overlap that I can see or after running your code.
Could you help please? Very much appreciated!
Never mind Jeff. Luckily, it occurred to me to delete a couple of pivot tables and those were causing the glitch…somehow!
Best,
I have the same issue as Mirko above.. “No overlaping found” but still the error “Pivot can’t overlap another pivot…”.
@Jeff Wier – Did you find a solution?
@Johnsen Can you share your file with me?
Pro tip — this will not function on hidden worksheets. Otherwise very helpful!
@Jeff Weir – Sorry no. I hope you could help anyway.
Just thought I’d add an extra note in case anyone else experiences the error code and its not as a result of any overlapping pivots.
Because I require my pivottables in a report to always have consistent column and row headers I have a hidden static table and an input table (with the same column headings) which receives data pasted in by users. These are then combined using an append query (within Excel Queries & Connections option) which my pivottables then refresh from, rather than from just the single user input table.
During testing, I experienced if the user input table is empty when attempting to refresh a pivottable this error code is encountered. As soon as 1 line of dummy data is added to the user input table the error code no longer results.
Thank you soooooo much!!!
It’s almost 7pm on a friday night and your macro worked perfectly which means I can finish my report and enjoy my weekend :D
you’re a true hero!
Thanks Pernette :-)
Hey, thanks so much, the code seems to work great (I think)! However, I now get this message:
Table57 ‘Stats’!$A$14:$Y$20
How do I know which table is number 57?! Sorry, I am a bit of a novice!
Hey,
This doesn’t work when you click on refresh data. It works only when the sheets are already set. When I run this code, it shows ‘ No overlaps found’. But, when I refresh the whole sheet, I see the same error. Please help me out. This is really frustrating.
Excellent….was scratching my head over this one for a while
Hi all
I am experiencing the same issue as Mirko and JK ,
I then moved the table to ensure no overlaps but still get the error.
Has anybody found a solution to this?
I have same situation of mirko jk and palesa. no foud messag but error on refrash
Thanks so much for this however I am getting the same error msg as those using office 365. did anybody find a solution to this?
You are brilliant and a lifesaver. THANK YOU!!!
I am getting the same syntax error on Sub M_snb.
What was the fix on this line of code:
If j it.ListObjects.Count Then Set c00 = it.PivotTables(j – it.ListObjects.Count).TableRange2
I’m guessing that was a ‘not equal to’ that WordPress thinks was an html tag
If (Not Intersect(Range(sn(jj)), pp) Is Nothing) Then
Method intersect of object _Global failed