Options disapear when clicked in list box

czag10

New Member
Joined
Oct 31, 2013
Messages
1
When I run the following code the values in the called sheet populate into the list box. However, when I try to click them on the user form sheet, the values disappear and I get a blank box. Can anybody help? Thanks!

Code:
Private Sub Product_Change()
Application.EnableEvents = False
   Product.Clear
    Application.EnableEvents = True
    
    Select Case BusinessChannel.Value
        Case "Stores"
           Product.List = Sheets(4).Range("C1:C3477").Value
        Case "Dealers"
             Product.List = Sheets(5).Range("C1:C34").Value
        Case "National Accounts"
            Product.AddItem "Please enter product in adjacent cell."
            End Select
End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi and Welcome to the Board,

From your description, it sounds like you have a ListBox that's been named "Product" and it is on a UserForm (not embedded in a Worksheet).
Is that correct?

If so, the problem is that this Product_Change will run anytime an item is selected from the Listbox. At the start of the code, the Product.Clear statement clears the list which causes the event to trigger itself.

It looks like you've tried to prevent the code from triggering itself by using
Application.EnableEvents = False
...however that has no effect on events of Form Controls.

I'd suggest you take the code that populates the ListBox out of this this procedure and move it to the UserForm_Initialize event or to a separate Sub that can be called whenever the Listbox needs to be re-populated.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top