triggering different macros from list box?

H

hammer

Hi ,
I have a list box populated with 5 items, lets call them Monday-Friday, how
can I trigger I separate macro , on each selection , rather than the default
one for the listbox.

Any help will be gratefully received.


Cheers Jamie

--


---------------------------------------------------------------------
"Are you still wasting your time with spam?...
There is a solution!"

Protected by GIANT Company's Spam Inspector
The most powerful anti-spam software available.
http://www.giantcompany.com
 
D

David Hager

You can use a Select Case statement in your default procedure which uses the
return value to run a specified procedure.
 
H

Harald Staff

Hi Jamie

You can't. You let the only default one decide which one to call from itself, like this:

Select Case Listbox1.Listindex
Case 0
Call Macro15
Case 1
Call Macro306
Case 2
Call YourParents
Case Else
Call FormatHarddrive
End Select
 
R

Roger Whitehead

Run a Select Case statement based on the ListBox value, within the
Lisbox_Click procedure.

HTH
Roger
Shaftesbury (UK)
 
H

hammer

Sorry i should clarify I want to do this within excel, I don't know much
VB , Simple instructions would help.


cheers all thanks for swift reply .

jamie

--


---------------------------------------------------------------------
"Are you still wasting your time with spam?...
There is a solution!"

Protected by GIANT Company's Spam Inspector
The most powerful anti-spam software available.
http://www.giantcompany.com
 
H

Harald Staff

hammer said:
Sorry i should clarify I want to do this within excel, I don't know much
VB , Simple instructions would help.

Is the list in a spreadsheet or a userform or a dialog sheet ? Is it from the Forms
toolbar or from the controls toolbax ? How do you populate your list, is it a macro too ?
When do you want the macro to run, on clicking/arrowing to an item in the list or on
clicking an OK button after that ?

Apoliges for asking all this, but detailed info needs detailed background.
 
H

hammer

ok , thanks for help I will try to explain best I can,

the listbox is in a spreadsheet and is from the controls toolbox, I have
typed in the 5 entries, and I would like the macro to run with the entry is
highlighted/clicked on.


Thanks again for the help, greatly appreciated


Jamie

--


---------------------------------------------------------------------
"Are you still wasting your time with spam?...
There is a solution!"

Protected by GIANT Company's Spam Inspector
The most powerful anti-spam software available.
http://www.giantcompany.com
 
H

Harald Staff

In design mode, rightclick the listbox, choose View Code, paste the following into the
blank (?) sheet module that appear:

Private Sub ListBox1_Click()
Select Case ListBox1.ListIndex
Case 0
Call Macro1
Case 1
Call Macro2
Case Else
Beep
End Select
End Sub

Sub Macro1()
MsgBox "Yo"
End Sub

Sub Macro2()
MsgBox "Cheers"
End Sub

Replace "ListBox1" with whatever name the listbox has. And Macro1, 2 actions with what you
want done.
 
H

hammer

Well I am amazed at the speed and helpfulness of this group.
many thanks
Jamie
:)

--


---------------------------------------------------------------------
"Are you still wasting your time with spam?...
There is a solution!"

Protected by GIANT Company's Spam Inspector
The most powerful anti-spam software available.
http://www.giantcompany.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top