List Box Change Event

M

Martin

Hi,

I have a list box and have the following code in the worksheet module:

Private Sub MyListBox_Change()
Sheets("Report").Select
End Sub

My list box is called MyListBox but when I select it nothing happens. All I
want is to go to another sheet after the change occurs.

The only thing I can think is the name of my list box is incorrect but it
does show as MyListBox in the cell name drop down but it doesnt appear in the
defined names. Using 2003.

Can anyone see what I am doing wrong?

Thanks in advance

Martin
 
B

Bob Phillips

What sort of ListBox is it, from the Forms toolbar, or the Control tollbox?

If it is the former, you need to assign a macro, right-click>Assign Macro,
that does the sheet select. If if is the latter, you can add that code to
the worksheet's code module.
 
S

Stefi

Maybe you meant this:

Private Sub ListBox1_Click()
Sheets("Report").Select
End Sub

--
Regards!
Stefi



„Martin†ezt írta:
 
J

joel

The change function need to be in the VBA sheet where box is located.
usually add a break point in the macro to make sure the event i
occuring properly by selecting a line of code in the macro and hittin
F8. The code will no work unless the application.enableevents is set t
true
 
R

Ryan H

Are you actually changing something in the list box or are you just selecting
the list box. If you are just selecting the listbox I would use the
MyListBox_Click Event.

If you are changing something in the list box try:

Private Sub MyListBox_Change()
Sheets("Report").Activate
End Sub

or

Private Sub MyListBox_AfterUpdate()
Sheets("Report").Activate
End Sub
 
M

Martin

Hi,

I have tried all suggestions but it still doesnt want to work. Not sure
where to go from here, will have to think of other options...

Martin
 
S

Stefi

Check the name of your listbox in the properties window! It should be
MyListBox. If you create a new listbox, then Excel2003 gives it a name
ListBox1. MyListBox reminds me to the word usage of VBA Help. Maybe you
copied your code from there?
--
Regards!
Stefi



„Martin†ezt írta:
 
J

joel

Excel will automatically create the macro for you in the correc
location if you right click the listbox and select View Code. If you
are in 2003 you have to get into design mode by using the Triangle ICO
in the Control toolbox Toolbar (menu - View - Tool bars - contro
Toolbox)
 
M

Martin

Its a list box drawn from the Forms meny bar and not the control box menu
bar. Assuming that has an impact?
 
M

Martin

it is from the forms menu bar and I had assigned a macro previously but the
marco ran everytime I clicked in the list box and that included scrolling
down the list box.

So in effect it does work but it work on any click of the list box. I only
want it to work when I select a different record in the list box and
certainly not when I just scroll down
 
B

Bob Phillips

You could set the control Cell Link, and use worksheet change event to react
to any changes to that cell.
 

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