excel - OptionButton numbering loop -


hope have elegant solution simple problem!

i using activex option buttons, within worksheet , not userform or group box because of way sheet designed. code contained sub within option button code form.

this code pretty self-explanatory of i'm trying do:

public sub sectiond_click()  if optionbutton1.value = true     thisworkbook.sheets("boolean").range("b2").value = 1 elseif optionbutton2.value = true     thisworkbook.sheets("boolean").range("b2").value = 0 end if  if optionbutton3.value = true     thisworkbook.sheets("boolean").range("b3").value = 1 elseif optionbutton4.value = true     thisworkbook.sheets("boolean").range("b3").value = 0 end if  if optionbutton5.value = true     thisworkbook.sheets("boolean").range("b4").value = 1 elseif optionbutton6.value = true     thisworkbook.sheets("boolean").range("b4").value = 0 end if  end sub 

i make such number following "optionbutton" changes values using simple 'i = + 2' type statement seems vba variable/expression/object limitations not let me (sorry i'm noob here, not sure proper terminology should be).

would appreciate if point me in right direction here! have through 25 or option button pairs, , code 5 simple lines rather hundred on lines doing same thing!

i can name tune 1 line of code!!

public sub sectiond_click():    dim integer:    dim rw long:    rw = 2:    worksheets("sheet1"):    = 1 10 step 2:        if .oleobjects("optionbutton" & i).object.value then:            worksheets("boolean").cells(rw, "b").value = 0:        elseif .oleobjects("optionbutton" & i).object.value then:            worksheets("boolean").cells(rw, "b").value = 0:        end if:        rw = rw + 1:    next:    end with:end sub: 

but think 16 lines prettier.

public sub sectiond_click()     dim integer     dim rw long     rw = 2      worksheets("sheet1")         = 1 10 step 2             if .oleobjects("optionbutton" & i).object.value                 worksheets("boolean").cells(rw, "b").value = 0             elseif .oleobjects("optionbutton" & i).object.value                 worksheets("boolean").cells(rw, "b").value = 0             end if             rw = rw + 1         next     end end sub 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -