VBA UserForms : troble with updating the list box

rajkumar1989

New Member
Joined
Apr 24, 2014
Messages
1
Hi
I have Created a excel user form with three Combo box and list box with 3 columns.

When user selects a value from drop down list and click Add button it will be displayed in the list box - Done
When user selects a item in the list box it will again displays in drop down list - done
But when user selects the item in the list box and click update button its calling the ListBox _click () function, I dont want it to call the listbox_click fuction
PLease help. updating the code
Code for adding value from drop down list to list box

<code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; white-space: inherit;">
Code:
[COLOR=#00008B]Private [/COLOR][COLOR=#00008B]Sub[/COLOR] cmdAdd_Click()
[COLOR=#00008B]Call[/COLOR] stValues.AddItem(AddPpayTierOption(cboPpayTier.Value))
lstValues.List(UBound(lstValues.List), COL_BRAND) = cboBrandTier.Value
lstValues.List(UBound(lstValues.List), COL_GEN) = cboGenTier.Value
[COLOR=#00008B]End[/COLOR] [COLOR=#00008B]Sub[/COLOR]
</code>
when user clicks the item in the list box it will display the value in drop down list


Code:
<code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; white-space: inherit;">[COLOR=#00008B]Private[/COLOR] [COLOR=#00008B]Sub[/COLOR] lstValues_Click()
[COLOR=#00008B]Dim[/COLOR] I [COLOR=#00008B]As[/COLOR] [COLOR=#00008B]Long
[/COLOR]cmdEdit.Enabled = [COLOR=#800000]True
[/COLOR]cmdRemove.Enabled = [COLOR=#800000]True[/COLOR] 
 [COLOR=#00008B]If[/COLOR] lstValues.ListIndex <> -[COLOR=#800000]1[/COLOR] [COLOR=#00008B]Then[/COLOR] 
   [COLOR=#00008B]For[/COLOR] I = [COLOR=#800000]0[/COLOR] [COLOR=#00008B]To[/COLOR] lstValues.ColumnCount - [COLOR=#800000]1[/COLOR] 
       [COLOR=#00008B]If[/COLOR] I = [COLOR=#800000]0[/COLOR] [COLOR=#00008B]Then[/COLOR]        
       cboPpayTier.Value = lstValues.Column(I) 
       [COLOR=#00008B]Else[/COLOR] 
       [COLOR=#00008B]If[/COLOR] I = [COLOR=#800000]1[/COLOR] [COLOR=#00008B]Then[/COLOR]        
       cboBrandTier.Value = lstValues.Column(I) 
       [COLOR=#00008B]Else[/COLOR] 
       [COLOR=#00008B]If[/COLOR] I = [COLOR=#800000]2[/COLOR] [COLOR=#00008B]Then[/COLOR]        
       cboGenTier.Value = lstValues.Column(I) 
       [COLOR=#00008B]End[/COLOR] [COLOR=#00008B]If[/COLOR] 
       [COLOR=#00008B]End[/COLOR] [COLOR=#00008B]If[/COLOR] 
       [COLOR=#00008B]End[/COLOR] [COLOR=#00008B]If[/COLOR] 
   [COLOR=#00008B]Next[/COLOR] I
[COLOR=#00008B]End[/COLOR] [COLOR=#00008B]If
[/COLOR]</code>[COLOR=#000000][FONT=Arial]End Sub[/FONT][/COLOR]

when user click the update button code.

when it goes to lstValues.Column(j) = cboPpayTier.Value line its calling the lstValues_Click() fuction I dont want code to call that fuction. Please Help

Code:
<code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; white-space: inherit;">[COLOR=#00008B]Private[/COLOR] [COLOR=#00008B]Sub[/COLOR] cmdEdit_Click()
[COLOR=#00008B]Dim[/COLOR] j [COLOR=#00008B]As[/COLOR] [COLOR=#00008B]Long[/COLOR][COLOR=#00008B]Dim[/COLOR] var [COLOR=#00008B]As[/COLOR] [COLOR=#00008B]Variant[/COLOR] 
[COLOR=#00008B]If[/COLOR] lstValues.ListIndex <> -[COLOR=#800000]1[/COLOR] [COLOR=#00008B]Then[/COLOR] 
       [COLOR=#00008B]For[/COLOR] j = [COLOR=#800000]0[/COLOR] [COLOR=#00008B]To[/COLOR] lstValues.ColumnCount - [COLOR=#800000]1[/COLOR] 
           [COLOR=#00008B]If[/COLOR] j = [COLOR=#800000]0[/COLOR] [COLOR=#00008B]Then[/COLOR]            
           lstValues.Column(j) = cboPpayTier.Value 
           [COLOR=#00008B]Else[/COLOR]            
[COLOR=#00008B]           If[/COLOR] j = [COLOR=#800000]1[/COLOR] [COLOR=#00008B]Then[/COLOR] 
           lstValues.Column(j) = cboBrandTier.Value 
           [COLOR=#00008B]Else[/COLOR] 
           [COLOR=#00008B]If[/COLOR] j = [COLOR=#800000]2[/COLOR] [COLOR=#00008B]Then[/COLOR] 
           lstValues.Column(j) = cboGenTier.Value 
           [COLOR=#00008B]End[/COLOR] [COLOR=#00008B]If[/COLOR] 
           [COLOR=#00008B]End[/COLOR] [COLOR=#00008B]If[/COLOR] 
           [COLOR=#00008B]End[/COLOR] [COLOR=#00008B]If[/COLOR] 
       [COLOR=#00008B]Next[/COLOR] j 
   [COLOR=#00008B]End[/COLOR] [COLOR=#00008B]If
[/COLOR][COLOR=#00008B]End[/COLOR] [COLOR=#00008B]Sub
[/COLOR]</code>

please let me for more clarification.. thanks in advance
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Have you tried putting Application.EnableEvents=False before the lstValues.Column(j) = cboPpayTier.Value section, and Application.EnableEvents=True afterwards?
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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