Using VBA to systematically define the linked cell for a group of check boxes (excel) -


in spreadsheet have large number of pre-existing check-boxes, setting linked cell of each manually tedious task.

i hope group large numbers of them, , write vba code achieves:

i = 1 n = number of checkboxes in group while < n loop checkbox in 'group x', assign linked cell cell (range a1-->z1) end loop 

obviously isn't vba, i'm not familiar syntax, know a) if possible execute such function (i.e. grouped elements + assigning linked cells) b) commands / syntax need lookup write it.

many thanks

this code want:

sub linkfromgroup() dim g              ' put groups in variable dim gc integer  ' group count - number of elements in group dim r range     ' points cell link              set r = range("a1") ' point cell a1 -  ' know group when can count objects in group ' if try count objects don't exist error. ' trap following line: on error resume next   ' turn off screen updating while macro runs - or flicker application.screenupdating = false  ' loop on "shapes" in sheet1. group special kind of shape each g in sheets("sheet1").shapes   ' set count 0   gc = 0   ' see if value other 0   gc = g.groupitems.count ' on error go next line , gc still 0   if gc > 0     ii = 1 gc       g.groupitems.item(ii).select       selection.linkedcell = r.address  ' right assuming check boxes in groups...       selection.caption = "linked " & r.address ' not necessary - shows box linked what.        set r = r.offset(1, 0) ' next check box linked next cell down r     next ii   end if next g  application.screenupdating = true ' turn on normal operation again    end sub 

example of test sheet looks after running (there 2 groups , single check box):

enter image description here

single check box wasn't touched - groups were. never clicked box $a$8 value doesn't show either true or false.

you need open vba editor (alt-f11), insert module, , paste in above code. can run using (alt-f8) , picking macro list shown. there many other ways can this. sounds question can adapt code here. make sure on copy of spreadsheet first - until sure working want to!


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -