click event not working

Noz2k

Well-known Member
Joined
Mar 15, 2011
Messages
693
I have a combobox in a worksheet which when the user changes the value in the box works perfectly (it shows the list of values in column A on sheet 1). However when the user just clicks on the dropdown tab it doesn't update the list.

The code on both the click event and the change event is the same. Any idea why this would not work and how to solve it?

The code is as follows:

Code:
Private Sub cboReport_Click()
Sheets("Sheet1").UnProtect "abc123"
Dim cl As Range
Dim lngLastRow As Long
    lngLastRow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
 
    If lngLastRow <> 3 Then
        cboReport.List = Worksheets("Sheet1").Range("A3:A" & lngLastRow).Value
    Else
        cboReport.List = Worksheets("Sheet1").Range("A3:A4").Value
    End If
End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Any idea why the list would update when the value is changed, but not when the dropdown arrow is clicked?
 
Upvote 0
Hi there,

See VBA help for the Click event. In short, clicking on a combobox or the box's drop-down does not fire Click. If you select a value using the drop-down, the Click event is called, but only after the Change event has already run. The Change event is called regardless of whether the value is changed by typing in the box or selecting from the drop-down.
 
Upvote 0
Ah, I thought this might be the case.

Originally I had the code running on the activate event of the sheet, but that then caused a problem when the sheet was saved in a new workbook as it references sheet1 which doesn't exist in the new workbook.

What combobox event can I apply the code to so that it runs when the dropdown arrow is clicked?
 
Last edited:
Upvote 0
not to worry just found the dropdown button click which I didn't know existed.

Am still pretty inexperienced in Vba, and that just goes to show it.
 
Upvote 0
Glad you found it. Just for kicks, in a new/blank wb, you could make a userform with a combobox and a couple of other controls (just to see that we're taking focus away). In the form's module:
Rich (BB code):
Private Sub ComboBox1_Change()
    Debug.Print "Changed"
End Sub
    
Private Sub ComboBox1_Click()
    Debug.Print "Clicked"
End Sub
    
Private Sub ComboBox1_DropButt*******()
    Debug.Print "DropDownClicked"
End Sub
    
Private Sub UserForm_Initialize()
    With Me.ComboBox1
        .AddItem 1
        .AddItem 24
        .AddItem 23
        .AddItem 3
        .AddItem 4
    End With
End Sub
If you reduce vbide and excel's windows to half screen ea, you can run the form and watch what gets fired and the order, in the immediete window.
 
Upvote 0
Originally I had the code running on the activate event of the sheet, but that then caused a problem when the sheet was saved in a new workbook as it references sheet1 which doesn't exist in the new workbook.

So does your Click code, so how does that still work? (or doesn't it?)
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,239
Members
452,898
Latest member
Capolavoro009

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