Need to open a Message Box from a ComboBox, in Excel 2007

curiouswebster
curiouswebster used Ask the Experts™
on
I am trying to write my first VBA function in Excel and do not know how to get the code associated with a given ComboBox. So I thought opening a MessageBox would at least give me confirmation that it was opening correctly.

I already know how to fill a combo box with values.

So, please explain, step by step, how to get to get a given combo box to open a Message Box when a given selection is made on the combo.

Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Private Sub ComboBox1_Change()
    MsgBox "combo change"
End Sub
curiouswebsterSoftware Engineer

Author

Commented:
Tahanks. BUt it does not work where I put it, since that's also new to me:)

I use Excel 2007.

1) From the Developer Tab I opened Visual Basic
2) Right clicked the Worksheet
3) Pasted in the code
4) Hit Save

But nowhere do I find how to name the control ComboBox1.

What am I missing??
curiouswebsterSoftware Engineer

Author

Commented:
Thanks!  It works!

I neded to let the form generate the full event and need to move the mouse away from the combo box for the message box to open.

Commented:
In design mode, assuming you're using ActiveX, you can just double click your combobox.  That should take you to the change "event" associated with that combobox.  That's where you'll enter your msgbox line.

See the attached file.  Probably obvious but make sure to enable macros.

See the code under sheet1 msgbox.xlsm

Commented:
Oh...sorry.  I guess I should have asked if you were using a form.

Thanks for the points.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial