excel vba - Auto-Filter Method Failing - Run-Time Error 1004 -
how doing?
here's question. i'm trying apply autofilter criterias dates depends on quarter of year are. here's code.
if fator = 1 datainicio = dateserial(year(date), 10, 1) datafinal = dateserial(year(date), 12, 31) elseif fator = 2 datainicio = dateserial(year(date), 1, 1) datafinal = dateserial(year(date), 3, 31) elseif fator = 3 datainicio = dateserial(year(date), 4, 1) datafinal = dateserial(year(date), 6, 30) elseif fator = 4 datainicio = dateserial(year(date), 7, 1) datafinal = dateserial(year(date), 9, 30) end if wb.sheets("change-order fup").activate if wb.sheets("change-order fup").autofiltermode = true , wb.sheets("change-order fup").filtermode = true wb.sheets("change-order fup").showalldata elseif wb.sheets("change-order fup").autofiltermode = false wb.sheets("change-order fup").cells(1, 1).autofilter end if wb.sheets("change-order fup").range("a:p").autofilter field:=5, criteria1:=">="& datainicio, operator:=xland, criteria1:="<=" & datafinal
i tried use criteria1 , criteria2, both criteria1, both criteria2 , didn't work. give me hand here?
thanks again support! cheers
autofilter can picky date formats. try converting double first:
wb.sheets("change-order fup").range("a:p").autofilter field:=5, criteria1:=">="& cdbl(datainicio), operator:=xland, criteria2:="<=" & cdbl(datafinal)
Comments
Post a Comment