2017-10-17 1 views
1

필자는 마침내 Excel에서 피벗 차트의 원본 데이터가 "피벗 테이블 32"에서 다음과 같이 바뀌는 버그를 수정했습니다. "피벗 테이블 3".피벗 차트가 다른 피벗 테이블로 변경됨 - Microsft Excel 버그

것은 내가 텍스트로 끝이 모든 편집을 손이었다 (발생을 중지 보인다.) 내 원래 스크립트가 실제로 다른 버그를 밝혀

. Excel은 모든 피벗 테이블 이름을 업데이트했지만 스크립트가 실행될 때 차트가 보이지 않으면 차트의 원본이 완전히 손실됩니다.

어쨌든 여기에 내가 작성한 VBA 스크립트가 있습니다.

Sub FixAllPivotTables() 

Dim pt As PivotTable 
Dim ws As Worksheet 

If MsgBox("This script is mostly harmless. It will add an 'x' to the end of every Pivot Table name to stop an Excel bug where sometimes Pivot Charts lose their connection to their original pivot. Pivot Charts that are visible work with just changing the name in code, but hidden ones lose their source data. So, this activates each sheet and then zooms to all. I assume it might break if your chart and your pivot table aren't on the same page? USE WITH CAUTION! Click 'Cancel' to quit gracefully without messing with anything.", vbOKCancel) = vbOK Then 

'change the settings 
For Each ws In ActiveWorkbook.Worksheets 
'Pivot Charts that are visible work with just changing the name in code, but hidden ones lose their source data. So, this activates each sheet and then zooms to all. I assume it might break if your chart and your pivot table aren't on the same page? USE WITH CAUTION! 
ws.Activate 
Cells.Select 
ActiveWindow.Zoom = True 
    For Each pt In ws.PivotTables 
    'This one changes the last character of the pivot name to append an "x" so that there are no issues 
    'with pivot charts losing their reference when there are >10 pivot tables. 
    If Right(pt.Name, 1) <> "x" Then 
     pt.Name = pt.Name + "x" 
     Debug.Print pt.Name + " I added an x" 
    Else 
     Debug.Print pt.Name + " had an x already" 
    End If 
    Next pt 
ActiveWindow.Zoom = 100 
Range("a1").Select 
Next ws 


MsgBox "Added an 'x' to the end of each pivot table name if it didn't have one already.", vbOKOnly 


Else 
MsgBox "Cancelled", vbOKOnly 
End If 

End Sub 

나는 등 트래핑,이 오류가없는 것을 알고하지만 당신은 경고없이 최악의 시간에 위력을 과시합니다 피벗 테이블 및 피벗 차트의 톤을 사용할 때,이 그 버그 중 하나입니다. 감사. Jon

답변

0

원본 데이터 피벗 테이블의 제목을 2로 끝나지 않는 것으로 변경하면 원래 버그가 방지되는 것 같습니다. 위에 제공된 스크립트를 사용하면 모든 피벗 챠트가 피벗 테이블과 동일한 페이지에있는 한 피할 수 있습니다.

Sub FixAllPivotTables() 

Dim pt As PivotTable 
Dim ws As Worksheet 

If MsgBox("This script is mostly harmless. It will add an 'x' to the end of every Pivot Table name to stop an Excel bug where sometimes Pivot Charts lose their connection to their original pivot. Pivot Charts that are visible work with just changing the name in code, but hidden ones lose their source data. So, this activates each sheet and then zooms to all. I assume it might break if your chart and your pivot table aren't on the same page? USE WITH CAUTION! Click 'Cancel' to quit gracefully without messing with anything.", vbOKCancel) = vbOK Then 

'change the settings 
For Each ws In ActiveWorkbook.Worksheets 
'Pivot Charts that are visible work with just changing the name in code, but hidden ones lose their source data. So, this activates each sheet and then zooms to all. I assume it might break if your chart and your pivot table aren't on the same page? USE WITH CAUTION! 
ws.Activate 
Cells.Select 
ActiveWindow.Zoom = True 
    For Each pt In ws.PivotTables 
    'This one changes the last character of the pivot name to append an "x" so that there are no issues 
    'with pivot charts losing their reference when there are >10 pivot tables. 
    If Right(pt.Name, 1) <> "x" Then 
     pt.Name = pt.Name + "x" 
     Debug.Print pt.Name + " I added an x" 
    Else 
     Debug.Print pt.Name + " had an x already" 
    End If 
    Next pt 
ActiveWindow.Zoom = 100 
Range("a1").Select 
Next ws 


MsgBox "Added an 'x' to the end of each pivot table name if it didn't have one already.", vbOKOnly 


Else 
MsgBox "Cancelled", vbOKOnly 
End If 

End Sub