checkbox - VBA multiple checkboxes to control multiple pivot tables -
again need little appreciate.
basically, on dashboard page have couple of checkboxes control numerous of pivot tables in background.
i have checkboxes called "definite", "tentative", "pending,", ... , corresponds values in pivot fields.
and have numerous of pivot tables called: "hidden_1" or "hidden_2" in different sheets same structure.
my idea if checked "definite", selected in pivot pivot tables in fields called "status". if "unchecked" checkbox, pivots react.
to used code create before , working well:
sub checkbox1() application.screenupdating = false on error resume next dim pt pivottable, wks worksheet each wks in activeworkbook.worksheets each pt in wks.pivottables pt if .name = "hidden_1" or .name = "hidden_2" .pivotfields("status").currentpage = "definite" end if end next pt next wks application.screenupdating = true end sub
however, code selects 1 value, can't have selected both "definite" , "pending" if checked boxes. right checkboxes has separate code assigned .currentpage = "checkboxname" changed..
i have 2 questions:
1) best way select multiple values. e.g. if checked boxes "definite" , "pending" checked, pivot tables should have selected 2 values "definite" , "pending" selected in "status" field
2) best way "dis-select" value? right now, procedure checkbox1 running everytime checkbox clicked. , want run when "checking" it. right trying link checkbox cell, e.g. "definite" has h10, code starts line:
if range("h10").value = true 'code select value in "status" field else 'code unselect value in "status" field end if
i should noted couldn't use activex checkbox because had error: "cannot insert object" , used form controls. read error somehow connected patch have installed.
thank help, matt
i worked on , found such solution:
sub checkbox1() dim choice1, choice2, choice3, choice4, choice5, choice6, choice7 dim opi pivotitem dim pt pivottable, wks worksheet if sheets("hidden").range("b6").value = "true" choice1 = "definite" end if if sheets("hidden").range("b7").value = "true" choice2 = "tentative" end if if sheets("hidden").range("b8").value = "true" choice3 = "hold/option" end if if sheets("hidden").range("b9").value = "true" choice4 = "pending" end if if sheets("hidden").range("b10").value = "true" choice5 = "waitlist" if sheets("hidden").range("b11").value = "true" choice6 = "lost" end if if sheets("hidden").range("b12").value = "true" choice7 = "cancelled" end if sheets("hidden_pivot1").pivottables("hidden_1").pivotfields("salesstatus").clearallfilters sheets("hidden_pivot1").pivottables("hidden_3").pivotfields("salesstatus").clearallfilters sheets("hidden_pivot2").pivottables("hidden_2").pivotfields("salesstatus").clearallfilters sheets("hidden_pivot2").pivottables("hidden_4").pivotfields("salesstatus").clearallfilters each wks in activeworkbook.worksheets each pt in wks.pivottables pt if .name = "hidden_1" or .name = "hidden_2" or .name = "hidden_3" or .name = "hidden_4" each opi in pt.pivotfields("salesstatus").pivotitems select case opi.name case choice1, choice2, choice3, choice4, choice5, choice6, choice7 case else opi.visible = false end select next end if end next pt next wks end sub
this work slow. better if macro add , delete items, instead of re-creating entire choice.
Comments
Post a Comment