excel vba - Unrelated Pivot Tables slowing loops to a crawl -


a change of scope project means 2 workbooks must become 1 workbook. workbook has 3 sheets: output (viewed end users,) data (used drop small sql queries onto sheet , run logic below,) , data2 has active connection db bigger queries on server via pivot tables.

this code (without data2 sheet in workbook) can loop through ~15k lines in less 5 seconds

for = sheets("data").range("a" & rows.count).end(xlup).row 1 step -1     if not (range("d" & i).value > qs) , (range("d" & i).value < qe)         range("d" & i).entirerow.delete      end if next 

upon adding new sheet (which has 2 pivot tables querying sql db, several fliters, , slicer each) single loop (which 1 of 8) takes long run haven't let finish. dropping break on "end if" , iterating through holding f5 shows code working properly. nothing on data2 sheet references outside of sheet. feel reason pivot tables refreshing through each iteration of loop no reason.

things have not helped:

pivottable("table1").manualupdate = true 

or

application.screenupdating = false 

or

application.calculation = xlmanual 

a slight modification doesn't address root problem might speed processing:

dim sht worksheet dim rngdel range  set sht = sheets("data") = 1 sht.range("a" & rows.count).end(xlup).row      if not (sht.range("d" & i).value > qs) , (sht.range("d" & i).value < qe)         if rngdel nothing             set rngdel = sht.range("d" & i).entirerow         else             set rngdel = application.union(rngdel, sht.range("d" & i).entirerow)         end if     end if next  if not rngdel nothing rngdel.delete 

@acantud's comment worth addressing: unqualified range objects can cause sorts of problems sheet being read/modified not 1 want.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -