excel - Autofilter in another sheet using VBA -
i intend filter values begins 314 in column f, , clear contents(entire row). workbook has 30,000+ rows , think looping not option when filtering in sheet(sa). recorded following code below.
sheets("sa").select selection.autofilter activesheet.range("$a$1:$af$30436").autofilter field:=6, criteria1:="=314*" _ , operator:=xland activecell.offset(-181, -2).range("a1:af30436").select activecell.activate selection.clearcontents when ran code, runtime error 1004 appears. think because of activecell, because ran code in different sheet(sb, button filtering sheets in sa found). possible fix this? suggestions?
this should work ,
sub filter() dim ws worksheet set ws = sheets("sheet1") ws.range("$a$1:$af$30436").autofilter field:=6, criteria1:="=314*" _ , operator:=xland dim lr long lr = ws.range("a" & ws.rows.count).end(xlup).row ws.range("a2:af" & lr).specialcells(xlcelltypevisible).clearcontents ws.autofiltermode = false end sub
Comments
Post a Comment