excel - Store location of command button cell address to variable in VBA -
okay i'm using excel , trying cell address based off location of command button i'm clicking. want store cell address in variable click button used in next code user form pops result of clicking button. ive looked @ link: store location of cell address variable in vba , similar i'm trying cant seem work activesheet.shapes(application.caller).topleftcell.address
gives address based off top left corner of command button. i'm trying way can use same code next part every similar button add without having manually change code based off button is.
i'm pretty new when comes excel , vba appreciated.
edit:
i tried adding code i'm getting runtime error '1004' unable buttons property of worksheet class. have this
sub button2_click() dim btrng range set btnrng = activesheet.buttons(application.caller).topleftcell msgbox btnrng.address btnrng.offset(3, 3) = "hello" formaddbill.show end sub
this button popping userform information input. error happening on set btnrng = activesheet.buttons(application.caller).topleftcell
if using application.caller assume buttons forms.control toolbox. makes life lot easier.
assign each button code example:
sub rng_butn_clicked() dim btrng range set btnrng = activesheet.buttons(application.caller).topleftcell msgbox btnrng.address btnrng.offset(3, 3) = "hello" end sub
if using command buttons activex toolbar, can bit confusing. doing 1 @ time easy enough
private sub commandbutton1_click() me.commandbutton1.topleftcell.offset(0, 1) = "hi" me.commandbutton1.topleftcell.offset(, 2).interior.color = vbblue msgbox me.commandbutton1.topleftcell.address end sub
but assigning 1 code many activex command buttons not easy, prefer use forms buttons if want assign 1 code many buttons.
edit: if getting error
you put code in command button. please reread answer.
Comments
Post a Comment