Hi folks, i keep getting errors with the second of the two macros below while PT.ManualUpdate=True is used. I am trying to speed up the filter selection process which looks at the value selected in a combo box and if that value does not equal the pivot item value it hides the pivot item. it loops through all pivot items. without the PT.ManualUPdate bit, the second macro delivers the correct result - it just takes forever and a day...
<font face=Calibri><SPAN style="color:#00007F">Sub</SPAN> ChooseMAM()<br><br>****<SPAN style="color:#00007F">Dim</SPAN> critRange <SPAN style="color:#00007F">As</SPAN> Range, c <SPAN style="color:#00007F">As</SPAN> Range, ws <SPAN style="color:#00007F">As</SPAN> Worksheet, PT <SPAN style="color:#00007F">As</SPAN> PivotTable, pi <SPAN style="color:#00007F">As</SPAN> PivotItem<br>****<SPAN style="color:#00007F">Set</SPAN> critRange = Worksheets("Annual Results").Range("C2")<br>****<SPAN style="color:#00007F">Dim</SPAN> strFields <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>, strFields2 <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br>****<SPAN style="color:#00007F">Dim</SPAN> graphSheets <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Variant</SPAN><br>****strFields = Worksheets("Annual Results").Range("b2").Value<br>****strFields2 = "Debtor Normal Name"<br>****PT.ManualUpdate = <SPAN style="color:#00007F">True</SPAN><br>****strValue = critRange.Value<br>****Worksheets("Annual Results").Range("D3").Value = "0"<br><br>****<SPAN style="color:#00007F">Set</SPAN> graphSheets = Sheets(Array("Rep Sales Data", "TY Sales Data"))<br><br>****<SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> ws <SPAN style="color:#00007F">In</SPAN> graphSheets<br>********<SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> PT <SPAN style="color:#00007F">In</SPAN> ws.PivotTables<br>************<SPAN style="color:#00007F">With</SPAN> PT.PivotFields(strFields2)<br>****************.ClearAllFilters<br>************<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br><br>************<SPAN style="color:#00007F">With</SPAN> PT.PivotFields(strFields)<br>****************.ClearAllFilters<br>****************<SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> pi <SPAN style="color:#00007F">In</SPAN> PT.PivotFields(strFields).PivotItems<br>********************<SPAN style="color:#00007F">If</SPAN> pi.Value = strValue <SPAN style="color:#00007F">Then</SPAN><br>************************.CurrentPage = strValue<br>************************<SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">For</SPAN><br>********************<SPAN style="color:#00007F">Else</SPAN><br>************************.CurrentPage = "(All)"<br>********************<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>****************<SPAN style="color:#00007F">Next</SPAN> pi<br>************<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>********<SPAN style="color:#00007F">Next</SPAN> PT<br>****<SPAN style="color:#00007F">Next</SPAN> ws<br>****PT.ManualUpdate = <SPAN style="color:#00007F">False</SPAN><br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br><SPAN style="color:#00007F">Sub</SPAN> ChooseAccount()<br><br>****<SPAN style="color:#00007F">Dim</SPAN> AccountRange <SPAN style="color:#00007F">As</SPAN> Range, c <SPAN style="color:#00007F">As</SPAN> Range, ws <SPAN style="color:#00007F">As</SPAN> Worksheet, PT <SPAN style="color:#00007F">As</SPAN> PivotTable, pi <SPAN style="color:#00007F">As</SPAN> PivotItem<br>****<SPAN style="color:#00007F">Dim</SPAN> strDebtorName <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>, strFields2 <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br>****<SPAN style="color:#00007F">Dim</SPAN> graphSheets <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Variant</SPAN><br>****<SPAN style="color:#00007F">Dim</SPAN> j <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br><br>****strFields2 = "Debtor Normal Name"<br>****<SPAN style="color:#00007F">Set</SPAN> AccountRange = Worksheets("Annual Results").Range("c3")<br>****strDNValue = AccountRange.Value<br>****PT.ManualUpdate = <SPAN style="color:#00007F">True</SPAN><br>****<SPAN style="color:#00007F">Set</SPAN> graphSheets = Sheets(Array("Rep Sales Data", "TY Sales Data"))<br><br>****<SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> ws <SPAN style="color:#00007F">In</SPAN> graphSheets<br>********<SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> PT <SPAN style="color:#00007F">In</SPAN> ws.PivotTables<br><br>************<SPAN style="color:#00007F">With</SPAN> PT.PivotFields(strFields2)<br>****************<SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> pi <SPAN style="color:#00007F">In</SPAN> PT.PivotFields(strFields2).PivotItems<br><br>********************<SPAN style="color:#00007F">For</SPAN> j = 1 <SPAN style="color:#00007F">To</SPAN> .PivotItems.Count<br>************************<SPAN style="color:#00007F">If</SPAN> .PivotItems(j) <> strDNValue And _<br>************************** .PivotItems(j).Visible = <SPAN style="color:#00007F">True</SPAN> <SPAN style="color:#00007F">Then</SPAN><br>****************************.PivotItems(j).Visible = <SPAN style="color:#00007F">False</SPAN><br>************************<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>********************<SPAN style="color:#00007F">Next</SPAN> j<br><br>****************<SPAN style="color:#00007F">Next</SPAN> pi<br>************<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>********<SPAN style="color:#00007F">Next</SPAN> PT<br>****<SPAN style="color:#00007F">Next</SPAN> ws<br>****PT.ManualUpdate = <SPAN style="color:#00007F">False</SPAN><br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
the macros are an amalgam of other macros so there should be some cleanups to do still, so any suggestions in that direction would also be appreciated.
<font face=Calibri><SPAN style="color:#00007F">Sub</SPAN> ChooseMAM()<br><br>****<SPAN style="color:#00007F">Dim</SPAN> critRange <SPAN style="color:#00007F">As</SPAN> Range, c <SPAN style="color:#00007F">As</SPAN> Range, ws <SPAN style="color:#00007F">As</SPAN> Worksheet, PT <SPAN style="color:#00007F">As</SPAN> PivotTable, pi <SPAN style="color:#00007F">As</SPAN> PivotItem<br>****<SPAN style="color:#00007F">Set</SPAN> critRange = Worksheets("Annual Results").Range("C2")<br>****<SPAN style="color:#00007F">Dim</SPAN> strFields <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>, strFields2 <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br>****<SPAN style="color:#00007F">Dim</SPAN> graphSheets <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Variant</SPAN><br>****strFields = Worksheets("Annual Results").Range("b2").Value<br>****strFields2 = "Debtor Normal Name"<br>****PT.ManualUpdate = <SPAN style="color:#00007F">True</SPAN><br>****strValue = critRange.Value<br>****Worksheets("Annual Results").Range("D3").Value = "0"<br><br>****<SPAN style="color:#00007F">Set</SPAN> graphSheets = Sheets(Array("Rep Sales Data", "TY Sales Data"))<br><br>****<SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> ws <SPAN style="color:#00007F">In</SPAN> graphSheets<br>********<SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> PT <SPAN style="color:#00007F">In</SPAN> ws.PivotTables<br>************<SPAN style="color:#00007F">With</SPAN> PT.PivotFields(strFields2)<br>****************.ClearAllFilters<br>************<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br><br>************<SPAN style="color:#00007F">With</SPAN> PT.PivotFields(strFields)<br>****************.ClearAllFilters<br>****************<SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> pi <SPAN style="color:#00007F">In</SPAN> PT.PivotFields(strFields).PivotItems<br>********************<SPAN style="color:#00007F">If</SPAN> pi.Value = strValue <SPAN style="color:#00007F">Then</SPAN><br>************************.CurrentPage = strValue<br>************************<SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">For</SPAN><br>********************<SPAN style="color:#00007F">Else</SPAN><br>************************.CurrentPage = "(All)"<br>********************<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>****************<SPAN style="color:#00007F">Next</SPAN> pi<br>************<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>********<SPAN style="color:#00007F">Next</SPAN> PT<br>****<SPAN style="color:#00007F">Next</SPAN> ws<br>****PT.ManualUpdate = <SPAN style="color:#00007F">False</SPAN><br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br><SPAN style="color:#00007F">Sub</SPAN> ChooseAccount()<br><br>****<SPAN style="color:#00007F">Dim</SPAN> AccountRange <SPAN style="color:#00007F">As</SPAN> Range, c <SPAN style="color:#00007F">As</SPAN> Range, ws <SPAN style="color:#00007F">As</SPAN> Worksheet, PT <SPAN style="color:#00007F">As</SPAN> PivotTable, pi <SPAN style="color:#00007F">As</SPAN> PivotItem<br>****<SPAN style="color:#00007F">Dim</SPAN> strDebtorName <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>, strFields2 <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br>****<SPAN style="color:#00007F">Dim</SPAN> graphSheets <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Variant</SPAN><br>****<SPAN style="color:#00007F">Dim</SPAN> j <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br><br>****strFields2 = "Debtor Normal Name"<br>****<SPAN style="color:#00007F">Set</SPAN> AccountRange = Worksheets("Annual Results").Range("c3")<br>****strDNValue = AccountRange.Value<br>****PT.ManualUpdate = <SPAN style="color:#00007F">True</SPAN><br>****<SPAN style="color:#00007F">Set</SPAN> graphSheets = Sheets(Array("Rep Sales Data", "TY Sales Data"))<br><br>****<SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> ws <SPAN style="color:#00007F">In</SPAN> graphSheets<br>********<SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> PT <SPAN style="color:#00007F">In</SPAN> ws.PivotTables<br><br>************<SPAN style="color:#00007F">With</SPAN> PT.PivotFields(strFields2)<br>****************<SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> pi <SPAN style="color:#00007F">In</SPAN> PT.PivotFields(strFields2).PivotItems<br><br>********************<SPAN style="color:#00007F">For</SPAN> j = 1 <SPAN style="color:#00007F">To</SPAN> .PivotItems.Count<br>************************<SPAN style="color:#00007F">If</SPAN> .PivotItems(j) <> strDNValue And _<br>************************** .PivotItems(j).Visible = <SPAN style="color:#00007F">True</SPAN> <SPAN style="color:#00007F">Then</SPAN><br>****************************.PivotItems(j).Visible = <SPAN style="color:#00007F">False</SPAN><br>************************<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>********************<SPAN style="color:#00007F">Next</SPAN> j<br><br>****************<SPAN style="color:#00007F">Next</SPAN> pi<br>************<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>********<SPAN style="color:#00007F">Next</SPAN> PT<br>****<SPAN style="color:#00007F">Next</SPAN> ws<br>****PT.ManualUpdate = <SPAN style="color:#00007F">False</SPAN><br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
the macros are an amalgam of other macros so there should be some cleanups to do still, so any suggestions in that direction would also be appreciated.
Last edited: