Image

Imageinsaint wrote in Imagevbdev stumped

[VBA] Combo boxes in Excel

Hi everyone.

I hope this is the right place to post this. I'm creating a form in MS Excel using ActiveX controls rather than a user form. I have several combo boxes and a "Reset" button that is supposed to clear them.

Items for the boxes come from another sheet in the workbook. Selecting something from one of the main boxes (i.e. cbMain1) populates the related sub box (cbSub1) with values relating to the main choice. The Reset button is supposed to clear the sub boxes and return all main boxes to their default values.

It used to work fine up until yesterday. Now 3 of the boxes (cbSub1, cbSub2, and cbSub3) aren't being cleared for some reason. The other three are still working as expected. I've absolutely no idea what may have affected this. I haven't touched this procedure at all and it seems fairly straightforward.

Private Sub cmdCancel_Click()
    Set xlDataSheet = Sheets(2)
    
    ' clear all menus
    cbMain1.Clear
    cbMain2.Clear
    cbMain3.Clear
    
    cbSub1.Clear
    cbSub2.Clear
    cbSub3.Clear
    
    cbSub1.Value = vbNullString
    cbSub2.Value = vbNullString
    cbSub3.Value = vbNullString
    
    ' Populate main header menus
    With cbMain1
        .AddItem ("Select main evaluation area:")
        .AddItem (xlDataSheet.Range("C2"))
        .AddItem (xlDataSheet.Range("C10"))
        .AddItem (xlDataSheet.Range("C14"))
        .AddItem (xlDataSheet.Range("C20"))
        .AddItem (xlDataSheet.Range("C24"))
    End With
    
    With cbMain2
        .AddItem ("Select main evaluation area:")
        .AddItem (xlDataSheet.Range("C2"))
        .AddItem (xlDataSheet.Range("C10"))
        .AddItem (xlDataSheet.Range("C14"))
        .AddItem (xlDataSheet.Range("C20"))
        .AddItem (xlDataSheet.Range("C24"))
    End With
    
    With cbMain3
        .AddItem ("Select main evaluation area:")
        .AddItem (xlDataSheet.Range("C2"))
        .AddItem (xlDataSheet.Range("C10"))
        .AddItem (xlDataSheet.Range("C14"))
        .AddItem (xlDataSheet.Range("C20"))
        .AddItem (xlDataSheet.Range("C24"))
    End With
    
    cbMain1.Value = "Select main evaluation area:"
    cbMain2.Value = "Select main evaluation area:"
    cbMain3.Value = "Select main evaluation area:"
End Sub


Help?