vba - Excel Macro Copying A Single Row It Shouldn't -
i have macro designed copy row's contents separate sheet based on value contained in 1 of several columns click of button, contained on originating sheet:
private sub commandbutton1_click() application.screenupdating = false application.enableevents = false application.calculation = xlcalculationmanual dim longlastrow long dim cancelled worksheet, discontinued worksheet, notconf24 worksheet, esdout worksheet, notconfship worksheet, notconfship24 worksheet set cancelled = sheets("cancelled") set discontinued = sheets("discontinued") set notconf24 = sheets("notconfavail24hr") set esdout = sheets("esdoutsideleadtime") set notconfshiplead = sheets("notconfbutshipinlead") set notconfship24 = sheets("notconfship24hrs") longlastrow = cells(rows.count, "a").end(xlup).row range("a2", "t" & longlastrow) .autofilter .autofilter field:=13, criteria1:="yes" .copy cancelled.range("a1") .autofilter field:=14, criteria1:="yes" .copy discontinued.range("a1") .autofilter field:=15, criteria1:="no" .copy notconf24.range("a1") .autofilter field:=16, criteria1:="yes" .copy notconfshiplead.range("a1") .autofilter field:=18, criteria1:="no" .copy notconfship24.range("a1") .autofilter end application.screenupdating = true application.enableevents = true application.calculation = xlcalculationautomatic end sub the problem i'm having it's copying first row in range, a2, every sheet if doesn't meet criteria. have little experience working vba. got macro here , have perused significant number of other articles pertaining type of function, have tried many of solutions offered, , have come short each time.
in post linked above, 1 user had similar problem (it copied first row in range), , suggested due fact column a might not contain value on actual last row content; however, in case does. columns between a , t have value.
other that, macro works great! able sort ~10,000 rows in less second.
pls try this:
private sub commandbutton1_click() application.screenupdating = false application.enableevents = false application.calculation = xlcalculationmanual dim longlastrow long dim cancelled worksheet, discontinued worksheet, notconf24 worksheet, esdout worksheet, notconfship worksheet, notconfship24 worksheet set cancelled = sheets("cancelled") set discontinued = sheets("discontinued") set notconf24 = sheets("notconfavail24hr") set esdout = sheets("esdoutsideleadtime") set notconfshiplead = sheets("notconfbutshipinlead") set notconfship24 = sheets("notconfship24hrs") longlastrow = cells(rows.count, "a").end(xlup).row dim cpyrng range set cpyrng = range("a3", "t" & longlastrow) range("a2", "t" & longlastrow) .autofilter .autofilter field:=13, criteria1:="yes" cpyrng.copy cancelled.range("a1") .autofilter field:=14, criteria1:="yes" cpyrng.copy discontinued.range("a1") .autofilter field:=15, criteria1:="no" cpyrng.copy notconf24.range("a1") .autofilter field:=16, criteria1:="yes" cpyrng.copy notconfshiplead.range("a1") .autofilter field:=18, criteria1:="no" cpyrng.copy notconfship24.range("a1") .autofilter end application.screenupdating = true application.enableevents = true application.calculation = xlcalculationautomatic end sub you change cpyrng. .offset(1).resize(.rows.count - 1). , skip out whole cpyrng-variable way...
still, i'm sure should easy fast solution :)
Comments
Post a Comment