Monday 13 January 2014

How to clear the data and history after clearing the Combobox while opening the workbook in VBA

While Opening the Workbook you want to clear the data and history of ComboBox.

Sub Workbook_Open()
On Error GoTo ErrorHandler
    With Sheet2
        .TextBox1.Value = Null
        .TextBox2.Value = Null
        .TextBox3.Value = Null
        .TextBox4.Value = Null
        .ComboBox1.Clear
         .ComboBox2.Clear
         .ComboBox1.ListIndex = -1
         .ComboBox2.ListIndex = -1
    End With
    Application.EnableEvents = True
ErrorHandler:
    Application.EnableEvents = False
End Sub

We have to clear the combobox to clear the items and we need to set the ListIndex=-1 then only we can able to show empty combobox