excel - Loop counter in checkbox name -
i trying create sheet have checkbox in each non-empty line. automatically adjust number of checkboxes created macro:
sub checkboxes()  dim integer  = 9 200 set curcell = activesheet.cells(i, 3)     if curcell.value > 1         activesheet.shapes("checkbox" & cstr(i)).visible = true     else         activesheet.shapes("checkbox" & cstr(i)).visible = false     end if     next  end sub i expect number of potential rows data not greater 200. macro checks if value in column c each line >1, if true checkbox visible, else it's hidden.
my problem don't know how put loop counter "i" shape name - got error using code above. can help?
i think more elegant solution.
this loops through shapes on activesheet , checks if msoolecontrolobject (see here more information on matter). 
sub checkboxes()  dim curcellvalue variant dim long     = 1 activesheet.shapes.count         if activesheet.shapes(i).type = msoolecontrolobject             curcellvalue = activesheet.cells(i, 3).value             if curcellvalue <> ""                 activesheet.shapes(i).visible = true             else                 activesheet.shapes(i).visible = false             end if         end if     next end sub so why "better"?
- you don't have "guess" how many values there be.
- if ever change name of checkbox script still working.
- this checks empty cells.
also note replaced set curcell = activesheet.cells(i, 3) curcellvalue = activesheet.cells(i, 3).value. don't need set object in every iteration. filling variable suffices.
but: check msoolecontrolobjects includes checkboxes, textboxes , like.
hth.
Comments
Post a Comment