excel - Why is this skipping one row of cells? -


i have macro filters spreadsheet department , copies & paste results appropriate departments worksheet. repeats each of 9 departments. working fine except doesn't copy , paste last line of data "punch press" section. shows cells highlighted data not transfer it.

any appreciated!

here's have:

sub updatetables()   'punchpress macro        sheets("audit scores").select     activesheet.range("$a$1:$al$118").autofilter field:=2, criteria1:= _         "punch press esp"       range("x1").select     range(selection, selection.end(xldown)).select     range(selection, selection.end(xltoright)).select       selection.copy     sheets("punch press").select     range("x1").select     activesheet.paste     columns("a:a").columnwidth = 17.57     columns("a:a").columnwidth = 20.57     rows("2:2").rowheight = 15     selection.rowheight = 15      range("a1").select  end sub     

basically using range(..) in incorrect manner. believe assuming enforces range on active sheet incorect. when run error.

i've update code run without performance enhancements. below worked me.

sub updatetables() 'punchpress macro      sheets("audit scores")         .autofiltermode = false '<~~remove filters         .range("$a$1:$al$118").autofilter field:=2, criteria1:="punch press esp"         .range("x1").select         .range(selection, selection.end(xldown)).select         .range(selection, selection.end(xltoright)).select     end      selection.copy      sheets("punch press")         .select         .range("x1").select         .paste         .columns("a:a").columnwidth = 17.57         .columns("a:a").columnwidth = 20.57         .rows("2:2").rowheight = 15         selection.rowheight = 15         .range("a1").select     end  end sub 

to add in little optimisation copying of values. copy method best because filtered sheet can done in 1 line. i've retrieved last row , column use instead of relying on selecting down , right stop on empty cell.

sub updatetables() 'punchpress macro      dim rs long, cs long      sheets("audit scores")         rs = .cells.find("*", , , , xlbycolumns, xlprevious).row         cs = .cells.find("*", , , , xlbyrows, xlprevious).column          .autofiltermode = false '<~~remove filters         .range("$a$1:$al$118").autofilter field:=2, criteria1:="punch press esp"         .range(.cells(1, "x"), .cells(rs, cs)).copy sheets("punch press").range("x1")     end      sheets("punch press")         .columns("a:a").columnwidth = 20.57         .rows("1:2").rowheight = 15         .activate         .range("a1").select     end  end sub 

i hope helps.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -