原有的數(shù)據(jù)項(xiàng)仍保留在數(shù)據(jù)透視字段下拉框中。
數(shù)據(jù)透視表的數(shù)據(jù)源可能改變,導(dǎo)致字段下拉列表中有些無(wú)用的數(shù)據(jù)項(xiàng)存在,例如有些銷售人員已經(jīng)離開(kāi)公司,但他們的名字仍然在數(shù)據(jù)透視表的數(shù)據(jù)項(xiàng)中存在。
盡管你每次更新數(shù)據(jù)透視表后,這些名字仍然與新名字同時(shí)顯示出來(lái).在下面的列表中,楊建新已經(jīng)被劉艷代替,但他的名字仍然存在。
手動(dòng)清除原有的數(shù)據(jù)項(xiàng)
從列表中手動(dòng)清除原有的數(shù)據(jù)項(xiàng)操作方法:
1. 將數(shù)據(jù)透視字段拖拉到數(shù)據(jù)透視表以外的區(qū)域.
2. 點(diǎn)擊數(shù)據(jù)透視表工具欄上的更新按鈕
3. 將數(shù)據(jù)透視字段拖拉回到數(shù)據(jù)透視表區(qū)域
編寫程序清除原有的數(shù)據(jù)項(xiàng)–Excel2002或更高版本
在Excel2002或更高版本中,你可以編寫程序改變數(shù)據(jù)透視表屬性,防止遺漏顯示數(shù)據(jù)項(xiàng)或清除已經(jīng)顯示的數(shù)據(jù)項(xiàng).
SubDeleteMissingItems2002All()
‘防止數(shù)據(jù)透視表中顯示無(wú)用的數(shù)據(jù)項(xiàng)
‘在Excel2002或更高版本中
‘如果無(wú)用的數(shù)據(jù)項(xiàng)已經(jīng)存在,
‘運(yùn)行這個(gè)宏可以更新
DimptAsPivotTable
DimwsAsWorksheet
ForEachwsInActiveWorkbook.Worksheets
ForEachptInws.PivotTables
pt.PivotCache.MissingItemsLimit=xlMissingItemsNone
Nextpt
Nextws
EndSub
編寫程序清除原有的數(shù)據(jù)項(xiàng)–Excel97/Excel2000
在較早的Excel版本中,運(yùn)行下列代碼可以清除數(shù)據(jù)透視表下拉表的原有數(shù)據(jù)項(xiàng).
SubDeleteOldItemsWB()
‘清除數(shù)據(jù)透視表中無(wú)用的數(shù)據(jù)項(xiàng)
‘單位MSKB(202232)
DimwsAsWorksheet
DimptAsPivotTable
DimpfAsPivotField
DimpiAsPivotItem
OnErrorResumeNext
ForEachwsInActiveWorkbook.Worksheets
ForEachptInws.PivotTables
pt.RefreshTable
ForEachpfInpt.VisibleFields
Ifpf.Name<>"Data"Then
ForEachpiInpf.PivotItems
Ifpi.RecordCount=0And_
Notpi.IsCalculatedThen
pi.Delete
EndIf
Next
EndIf
Next
Next
Next
EndSub