irrational userform/combobox behavior

J

Jacob

This has me baffled. It's going to be hard to explain. I will
simplify it as much as possible. I have a listbox a combobox a button
and a sheet. The listbox contains a list of numbers. when a number in
the listbox is clicked, that number is entered into the combobox using
this code:

Private Sub ListBoxW_Click()
UserFormDesign.ComboBoxWsections.Text = UserFormDesign.ListBoxW.Text
End Sub

alternatively, the number in the combobox can be changed directly with
it's pull down menu.

I use the following code to update a cell (sheet2-D284) in the sheet
with the combobox number, each time the combobox number changes:

Private Sub ComboBoxWsections_Change()
Sheets("sheet2").Range("D284").Value =
UserFormDesign.ComboBoxWsections.Text
End Sub

Up to this point, everything works successfully. Next, there is a
button on the userform (the same form that contains the combo and
listbox), which when clicked, runs a routine that copies the cell with
the combobox value to a different cell (sheet2-C28) and does some other
stuff, then it hides the userform and shows a sheet of results,
including the value in the first cell I mentioned (sheet2-D284).

here is the relevant code for when the button is clicked:

Private Sub CommandButtonWView_Click()
Call Module1.SingleW
Sheet5.Select
UserFormDesign.Hide
Application.WindowState = xlMaximized
End Sub

here is the relevant code within Module1.SingleW:

Sheets("sheet2").Range("C28").Value =
Sheets("sheet2").Range("D284").Value

here is the problem: when the value is updated via the listbox,
everything works correctly. when the value is set via the combobox,
the value defaults back to the last clicked listbox value. The value
to cell D284 does update after changing the combobox but somehow it
goes back to the previous listbox value after clicking the results
button. prehaps it is the value in the listbox that is still
highlighted when clicking the button.

I would appreciate any help I can get on this. It's driving me crazy.
Thanks.
 
J

Jacob

I think I have narrowed it down further.

the following code is being executed when the button is clicked, and I
do not want it to. I want it to be executed ONLY when the listbox is
clicked.

Private Sub ListBoxW_Click()
UserFormDesign.ComboBoxWsections.Text = UserFormDesign.ListBoxW.Text
End Sub

why would it be doing that?
 
K

KR

I can't see anything from your posted snippets; maybe post larger sections
of your code, for example everything in your button code?
Keith
 
J

Jacob

I solved it by changing the listbox click event to a mouseup event. it
still makes no sense why the listbox click event would execute when the
button was clicked, but this works fine.

thanks for looking at it though, and if you have any insight as to why
that might happen, please let me know.
 

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