excel - Adding a date filter search to a current autofilter VBA line -
i helped out immensely bobajob on question regarding autofilters. however, need complicate things slightly. following code allows user search small data sheet of products in excel , have auto filter. works splendidly (thanks again bobajob!!), need complicate adding date search function. file relates products , dates refer production dates, expiration dates, etc. original search function allowed brand searched, produced, , serial code number...but have add ability pull when these items manufactured between 2 dates, still retaining search criteria of manufactured, etc.
is best way modifying code below? or adding in separate module? can still link 2 fields, etc?
sub filterto1criteria() dim long sheet1 .autofiltermode = false .range("a9:j1018").autofilter = 1 10 if .cells(3, i) <> vbnullstring .range("a9:j1018").autofilter field:=i, criteria1:=.cells(3, i) end if next end end sub
thanks in advance!!
given i'm familiar original, i'll have go @ 1 too. following test row 3 (the first criteria) see if date, , if use row 3 , row 4 define range of dates filter on:
sub filterto1criteria() dim long sheet1 .autofiltermode = false .range("a9:j1018").autofilter = 1 10 if .cells(3, i) <> vbnullstring if isdate(.cells(3, i)) .range("a9:j1018").autofilter field:=i, criteria1:=">=" & clng(.cells(3, i)), criteria2:="<=" & clng(.cells(4, i)) else .range("a9:j1018").autofilter field:=i, criteria1:=.cells(3, i) end if end if next end end sub
note converted dates longs first, should rid of ambiguity in date localisation.
Comments
Post a Comment