excel - using checkboxes with userform -


i have user form designed 3 listboxes. 3 listboxes populated location 3 different sheets.

by selecting listbox, user can filter data in sheet "data".

if user selecting "bbe bebra" listbox1. find filtered result of bebra in sheet.

similary, if user selecting listbox2, same procedure followed , if user selecting listbox3, same procedure followed.

the user can also, select 3 checkbox , looks filtered result in sheet.

i have issues working code.

  1. if selecting checkboxes , click "filter" see filtered result. next time click on filter button see whole data sheet filters clear , checkboxes cleared.

can tell how can ?

eevrytime,  see previous checked boxes in userform. instead have clear checkbox. (this means, when click button in sheet displays userform should clear filter result.

below code, using in filter button

sub dofilter() dim strcriteria() string dim strcriteria2() string dim strcriteria3() string dim arridx integer dim arridx2 integer dim arridx3 integer dim xrow integer dim arrcounter integer dim lo listobject arridx = 0 arridx2 = 0 arridx3 = 0 xrow = 2 last(1, list.cells)     if list.cells(xrow, 2) = true         redim preserve strcriteria(0 arridx)         strcriteria(arridx) = list.cells(xrow, 3)         arridx = arridx + 1     end if next xrow xrow = 2 last(1, list.cells)     if list_man.cells(xrow, 2) = true         redim preserve strcriteria2(0 arridx2)         strcriteria2(arridx2) = list_man.cells(xrow, 3)         arridx2 = arridx2 + 1     end if next xrow  xrow = 2 last(1, list.cells) if list_s.cells(xrow, 2) = true redim preserve strcriteria3(0 arridx3) strcriteria3(arridx3) = list_s.cells(xrow, 3) arridx3 = arridx3 + 1 end if next xrow  set ws = thisworkbook.sheets("data") set lo = ws.listobjects("table7") if arridx = 0 , arridx2 = 0 , arridx3 = 0     'ws.usedrange.autofilter else     ws     lo        '.autofiltermode = true         ' .usedrange.autofilter         if arridx <> 0            .range.autofilter field:=13, criteria1:=array(strcriteria), operator:=xlfiltervalues         end if         if arridx2 <> 0            .range.autofilter field:=14, criteria1:=array(strcriteria2), operator:=xlfiltervalues         end if         if arridx3 <> 0        .range.autofilter field:=15, criteria1:=array(strcriteria3), operator:=xlfiltervalues         end if          if .autofilter.range.columns(1).specialcells(xlcelltypevisible).cells.count = 1             msgbox " filter has no result"         end if     end     end  dim long on error resume next      thisworkbook.worksheets("dev").pivottables("pivottable1").pivotfields("lo.")         .clearallfilters         = 1 .pivotitems.count             .pivotitems(i).visible = false         next        arrcounter = lbound(strcriteria) ubound(strcriteria)             .pivotitems(strcriteria(arrcounter)).visible = true         next arrcounter     end end if end sub 

i call function filter in button "filter". button "exit" have following code

private sub cbexit_click() if activesheet.filtermode activesheet.showalldata end if  sheets("dev").select sheets("dev").pivottables("pivottable1").pivotfields("development loc.").clearallfilters unload me  end sub 

you need keep track of current state using sort of flag. following:

private sub filter_click()    if filter.caption = "filter"       dofilter       filter.caption = "unfilter"    else       'do logic clear       filter.caption = "filter"    end if end sub 

this has added benefit of telling user next click of button do.


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -