excel - Hiding multiple rows based on cell values -
i have algorithm works fine hide rows where, in specified named range, given row has value 0. it's straightforward enough:
public sub masquerlignesazerorapport(rap worksheet) dim cell range rap.rows.hidden = false each cell in rap.range("ra_lignesazero") if round(cell.value, 0) = 0 cell.entirerow.hidden = true end if next cell end sub
this, however, takes bit of time when calculation , screen updating turned off , have tried different other methods without success (using filter , hiding visible rows removing filter unhides rows, same goes setting row height 0).
is there faster alternative ? can live slow algorithm welcome improvement macro may run against 1-6 reports in single run.
here few optimizations:
public sub masquerlignesazerorapport(rap worksheet) 'optimization #1: pointed out, turning off calculations ' , screen updating makes difference. application.calculation = xlcalculationmanual application.screenupdating = false rap.rows.hidden = false 'optimization #2: instead of loading each cell range, ' associated properties, load values ' 2 dimensional array. dim values() variant values = rap.range("ra_lignesazero") r = 1 ubound(values, 1) c = 1 ubound(values, 2) if round(values(r,c), 0) = 0 rap.rows(r).hidden = true 'optimization #3: if have determined ' row should hidden, no need keep ' looking @ cells in row - might break out of for: exit end if next next application.screenupdating = true application.calculation = xlcalculationautomatic end sub
Comments
Post a Comment