ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   command button()_click (https://www.excelbanter.com/excel-programming/333504-command-button-_click.html)

iamkeen

command button()_click
 

hi,
sorry if these questions have been asked many times.

i am working through various books on using vba within excel and in
each of the books i cant find any answers. Each of the books suggests
that you create a command button so that if you click on it it will run
your code. Is it possible to:

1. run the code by just pressing enter on your keyboard-ie if the value
in cell(1,1) is a certain thing ,just by pressing enter can it trigger
off the rest of the code instead of having to click on the command
button
2. is it possible to have the command button on the top tool bar and if
so how can i do this.


many thanks in advance


--
iamkeen
------------------------------------------------------------------------
iamkeen's Profile: http://www.excelforum.com/member.php...o&userid=17752
View this thread: http://www.excelforum.com/showthread...hreadid=384155


dominicb[_51_]

command button()_click
 

Good morning Iamkeen

1. The way to do this is run an event procedure, where the code is
asking, if this cell = x then ... To do this you need to enclose your
code in this (as opposed to the usual Sub x() / End Sub constuct):

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
Range)
End Sub

and put it into the ThisWorkbook section of the VBE (see here for more
details http://www.cpearson.com/excel/events.htm)

2. You can't put a command button in a toolbar - only on a worksheet.
You can add another icon to a toolbar. Tools Customize and under
Toolbars selext Add. Once you have a new toolbar choose an icon under
the commands tab and drag it to your toolbar. Once it's there right
click and a drop down menu will appear with plenty of options. Among
the options will be to rename the button, edit the button (if you come
over all artistic!) or to assign a macro.

HTH

DominicB


--
dominicb
------------------------------------------------------------------------
dominicb's Profile: http://www.excelforum.com/member.php...o&userid=18932
View this thread: http://www.excelforum.com/showthread...hreadid=384155


iamkeen[_2_]

command button()_click
 

hi dominicb

thankyou for the speady reply.much appreciated. i will be trying them
out later.
thanks once again


--
iamkeen
------------------------------------------------------------------------
iamkeen's Profile: http://www.excelforum.com/member.php...o&userid=17752
View this thread: http://www.excelforum.com/showthread...hreadid=384155


dominicb[_52_]

command button()_click
 

Hi Iamkeen

You're welcome. I appreciate the feedback.

DominicB


--
dominicb
------------------------------------------------------------------------
dominicb's Profile: http://www.excelforum.com/member.php...o&userid=18932
View this thread: http://www.excelforum.com/showthread...hreadid=384155


Bob Phillips[_6_]

command button()_click
 

"dominicb" wrote in
message ...
1. The way to do this is run an event procedure, where the code is
asking, if this cell = x then ... To do this you need to enclose your
code in this (as opposed to the usual Sub x() / End Sub constuct):

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
Range)
End Sub

and put it into the ThisWorkbook section of the VBE (see here for more
details http://www.cpearson.com/excel/events.htm)


If you use this method, you must ensure that you use a commandbuttonb from
the control toolbox. And it won't work just by using the Enter key.

You could also use a command button from the forms toolbar, but in this case
you just assign a macro that runs on a click. Again, it won't run from an
enter,




iamkeen[_3_]

command button()_click
 

hi dominicb,

just checked it and it works better than i thought.

thanks again


--
iamkeen
------------------------------------------------------------------------
iamkeen's Profile: http://www.excelforum.com/member.php...o&userid=17752
View this thread: http://www.excelforum.com/showthread...hreadid=384155



All times are GMT +1. The time now is 12:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com