Optimizing/Streamlining Excel VBA for Deleting empty columns -


i've been using code below jonhaus.hubpages.com remove empty columns have.

    'delete empty columns dim c integer c = activesheet.cells.specialcells(xllastcell).column     until c = 0     if worksheetfunction.counta(columns(c)) = 0             columns(c).delete     end if     c = c - 1 loop 

however, i've been writing vba, it's gotten kinda bloated , slow... i'm trying optimize , streamline code eliminating loops, copy/pastes, etc.

do y'all have suggestions code same thing (deleting entire emtpy columns) without requiring looping "do until/if/end if/loop" statements?

references: http://jonhaus.hubpages.com/hub/excel-vba-delete-blank-blank-columns http://www.ozgrid.com/vba/speedingupvbacode.htm

expanding on comment above, create range inside loop, delete once.

dim c integer dim rngdelete range  c = activesheet.cells.specialcells(xllastcell).column     until c = 0         if worksheetfunction.counta(columns(c)) = 0             'combine each empty column:             if not rngdelete nothing                 set rngdelete = application.union(rngdelete, columns(c))             else                 set rngdelete = columns(c)             end if         end if         c = c - 1     loop      'deletes empty columns @ once:     rngdelete.entirecolumn.delete  

the other obvious improvements disable application.screenupdating , set application.calculation = xlmanual during run-time. (remember restore normal functionalities @ end of subroutine.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -