I am creating a combobox for searching sheets using sheet name with autocomplete functionality, I am able to get the name of the sheets of a workbook in dropdown list but when i am typing few alphabets of the name of sheet, i want to display suggestions of all the sheets present with the alphabets i have written in the combobox.
Below is the code done till now, with which i am able to select the sheet name and nagivate to that sheet.
1st - Add a combobox into first sheet and name it (I called it cmbSheet). I used an ActiveX Combobox (in Excel 2007, under Developer tab).
2nd - Opened VBA and added the below code into workbook code. This code will populate the combobox with the sheet names every time the workbook is opened.
Private Sub Workbook_Open()
Dim oSheet As Excel.Worksheet
Dim oCmbBox As MSForms.ComboBox
Set oCmbBox = ActiveWorkbook.Sheets(1).cmbSheet
oCmbBox.Clear
For Each oSheet In ActiveWorkbook.Sheets
oCmbBox.AddItem oSheet.Name
Next oSheet
End Sub
3rd - Now, i went to the code of my first sheet (where the combobox has been added) and added the code that will activate the sheet chosen in the combobox. The code is:
Private Sub cmbSheet_Change()
ActiveWorkbook.Sheets(cmbSheet.Value).Activate
End Sub
Now, when the combobox value changes, the respective sheet is activated.