how to copy all of table information with dynamic vba cells in excel -
i have table in sheet shown below
also have vba codes in optionbuttons
. codes optionbuttons
looks this:
private sub optionbutton11_click() worksheets("sheet1").activate range("$j$6").activate activecell.formular1c1 = "=rc[-5]*4" activecell.offset(5, 0).select activecell.select activecell.formular1c1 = "=sum(r[-7]c:r[-1]c)" end sub
and this:
private sub worksheets("sheet1").activate range("$j$8").activate activecell.formular1c1 = "=rc[-5]*2" activecell.offset(3, 0).select activecell.select activecell.formular1c1 = "=sum(r[-7]c:r[-1]c)" end sub
i have 45 such tables on same sheet , not want code every radio button. code works 1st table how can copy rest?
i wanna sheet in attachment
you have first understand pattern followed code. if can identify pattern have use code buttons.
also instead of using
activex option button
, useform control option button
. reason can tie option buttons same code usingassign macro
the next trick use name option button in sequence can use number (for ex: 1 "option button 1") our calculations
here basic example on how use multiple buttons achieve same functionality
let's our worksheet looks this. want whichever button choose cell j in respective row should have value.
put code in module. next in each option button
, right click , click on assign macro
. choose common code wrote. in example choose sample
.
notice how use application.caller
name of option button achieve want.
sub sample() dim long = val(trim(replace(application.caller, "option button", ""))) sheet1.range("j" & + 1).value = "blah blah blah" end sub
in case code can written this. have identify pattern , amend below code accordingly.
sub sample() dim long dim multiplier long = val(trim(replace(application.caller, "option button", ""))) multiplier = + 3 sheet1.range("j" & + 5) .formular1c1 = "=rc[-5]" & "*" & multiplier .offset(i + 5, 0).formular1c1 = "=sum(r[-7]c:r[-1]c)" end end sub
note: above can achieved activex controls have work array controls shown in vba – control arrays
Comments
Post a Comment