excel - unchecking the checkbox in userform -


i have userform designed 3 listboxes multiple option.

also, have 3 commandbuttons, "filter", "unfilter" , "exit".

i have access userform button in sheet, below code.

sub dev() userform1.show end sub 

from userform, select checkboxes , click "filter". see filtered result in sheet "data".

the problem when clicking button sheet "data" listbox has previous selection. clear previous selection in list box. currently, have clear case in unfilter button.

i have in main command button.

i tried this

sub dev() userform1.show call userform1.cbunfilter end sub() 

but showed "invalid use of property error".

can me how can ?

this code filter button in userform

private sub cbfilter_click()    if cbfilter.caption = "filter"    call dofilter.dofilter    else    'do end if end sub 

this code unfilter button in userform

private sub cbunfilter_click() dim icount, jcount, kcount integer if cbunfilter.caption = "unfilter"  icount = 0 me!listbox1.listcount me!listbox1.selected(icount) = false next icount  jcount = 0 me!listbox2.listcount me!listbox2.selected(jcount) = false next jcount  kcount = 0 me!listbox3.listcount me!listbox3.selected(kcount) = false next kcount end if end sub 

could have unfilter function can called button in sheet.

this how userform looks. userform called button main sheet

the answer entirely depends on how 'remove' userform.

if unload form programmatically (ie unload userform1) or user closes userform manually (ie clicking red cross), current settings lost. haven't said how you've populated items in listboxes i've assumed you've done programmatically. if that's case, listboxes cleared - not selections, items too.

if hide form, can done programmatically (ie me.hide), current settings remain and, when show userform again settings visible.

i have made best guess @ mimicking structure, ie: have worksheet called "data" onto have inserted commandbutton. macro have assigned commandbutton called 'dev' , 'dev' code in module1.

the unload method

for case i've assumed "exit" command button contains following code:

private sub cbexit_click()     unload me end sub 

you populate listboxes in userform_initialize() event. (you can access routine event clicking on 'userform1`, selecting 'useform' in first combobox below menu bar , 'initialize' in second.) i've put sample arrays in code behind, you'd populate wish:

private sub userform_initialize()     dim arr(2) variant      arr(0) = array("a", "b", "c", "d", "e", "f", "g", "h")     arr(1) = array("a", "b", "c", "d", "e", "f")     arr(2) = array("a", "b", "c", "d")      me.listbox1.list = arr(0)     me.listbox2.list = arr(1)     me.listbox3.list = arr(2) end sub 

your 'dev' routine remain , each time useform becomes visible, listboxes cleared.

the hide method

for case i've assumed "exit" button code is:

private sub cbexit_click()     me.hide end sub 

in userform code, you'd have couple of routines, public 1 can called module , private 1 clear boxes:

public sub reset()     clearlistbox me.listbox1, me.listbox2, me.listbox3 end sub  private sub clearlistbox(paramarray lboxes() variant)     dim item variant     dim lbox msforms.listbox     dim long      each item in lboxes         set lbox = item         = 0 lbox.listcount             lbox.selected(i) = false         next     next end sub 

then 'dev' code be:

public sub dev()     userform1         .reset         .show     end end sub 

incidentally, 'unfilter' button call clearlistbox routine:

private sub cbunfilter_click()     clearlistbox me.listbox1, me.listbox2, me.listbox3 end sub 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -