ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Run a macro when new selection in listbox (https://www.excelbanter.com/excel-programming/284594-run-macro-when-new-selection-listbox.html)

Georg[_3_]

Run a macro when new selection in listbox
 
Hello

I have been struggling with a probable very basic task and
wonder if anyone could give me a hint. I have a worksheet
that contains a listbox. Every time the user changes the
selection of th listbox, I would like a macro to start
running. I have tried to use "Private Sub
Workbook_Calculate()". This does not seem to work when the
list choices are altered. Neither does the workbook.change
() seem to work.

Is there an easy way to initiate this when the user has
clicked on the control? And if so, how should I refer to
the listbox (I think it is called "list box 3").

Would be grateful for any hints.

Regards

G E O R G

patrick molloy

Run a macro when new selection in listbox
 
If you use the listbox from the Form's tool bar, then
right click on the listbox, select assign macro then
click NEW. This takes you to yhje code window with the
default procedure frame , just ass a call to your macro.
eg if your macro is called MyCode add 'Call MyCode' as
below:
Sub ListBox1_Change()
Call MyCode
End Sub


If your listbox is from the ActiveX toolbar (The Control
Toolbox) then right click on kit and hit View Code
again this takes you to the control's event handler, so
all you need to do is add the same call viz
Private Sub ListBox1_Click()
Call MyOtherSub
End Sub


Patrick Molloy
Microsoft Excel MVP

-----Original Message-----
Hello

I have been struggling with a probable very basic task

and
wonder if anyone could give me a hint. I have a

worksheet
that contains a listbox. Every time the user changes the
selection of th listbox, I would like a macro to start
running. I have tried to use "Private Sub
Workbook_Calculate()". This does not seem to work when

the
list choices are altered. Neither does the

workbook.change
() seem to work.

Is there an easy way to initiate this when the user has
clicked on the control? And if so, how should I refer to
the listbox (I think it is called "list box 3").

Would be grateful for any hints.

Regards

G E O R G
.



All times are GMT +1. The time now is 06:43 PM.

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