Excel VBA matrix of checkboxes - only one in column AND row(?) -


the one-sentence summary of problem sound familiar:

i have a, let's say, "matrix" of checkboxes, , want them behave radio buttons.

but: please don't tell me use radio buttons instead, unless know how group in way when check 1 of them, no other button can selected in same row , column.

i have column of items , each item has 3 checkboxes so:

player  c   a1  a2 ------------------ item1  [ ] [ ] [ ] item2  [ ] [ ] [ ] item3  [ ] [ ] [ ] item4  [ ] [ ] [ ] item5  [ ] [ ] [ ] item6  [ ] [ ] [ ] item7  [ ] [ ] [ ] ... itemn  [ ] [ ] [ ] 

for sake of explanation let's suppose items stand players on hockey team , want name captain , assistant captains. in ideal world, you'll select 3 players (1 captain c, 2 alternate captains a1 , a2). in scenario, following rules apply:

1. 1 player cannot hold more 1 role 2. same role cannot assigned more 1 person. 

so if select player3 captain, want see result

player  c   a1  a2 ------------------ item1      [ ] [ ] item2      [ ] [ ] item3  [x]         item4      [ ] [ ] item5      [ ] [ ] item6      [ ] [ ] item7      [ ] [ ] ... 

is doable without nasty coding? because nasty coding is, it's i'm not sure it's worth effort.

(also, don't want go fancy , stuff, want fancier than:

player   ------------- item1    [ ] item2    [ ] item3    [c] item4    [ ] item5    [a] item6    [a] item7    [ ] ... 

because first, still want little fancy, , secondly, checking checkboxes should perform other actions too.)

this code-snippet placed in code of worksheet want have checkboxes in should trick:

option explicit  private sub worksheet_selectionchange(byval target range)   application.enableevents = false   application.screenupdating = false   dim r range: set r = sheet1.range("b2:e10")    if not intersect(r, target) nothing     if target.countlarge = 1       if target = "[x]"         target = [ ]         intersect(sheet1.rows(target.row), r) = "[ ]"         intersect(sheet1.columns(target.column), r) = "[ ]"       else         intersect(sheet1.rows(target.row), r).clearcontents         intersect(sheet1.columns(target.column), r).clearcontents         target = "[x]"       end if     end if   end if    application.enableevents = true   application.screenupdating = true end sub 

note codename of sheet want on needs "sheet1", , need define name of range containing checkmarks in set-statement @ top of sub.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -