ComboBox Queries

K

K

The code below list all the sheets name of active workbook in drop
down list. Because of the code line ".CLEAR" I am not able to get
combobox value. I want that when I select sheet name in drop down
list that name should appear as combobox text or value. and also how
can i stop some one to write in combobox as i want if some one write
in combobox the msgbox should appear saying "Select from drop down
list". Please can any friend solve my these queries about combobox.
Thanks

Private Sub ComboBox1_DropButtonClick()
Dim Sh As Worksheet
With ComboBox1
.CLEAR
For Each Sh In ActiveWorkbook.Sheets
If Sh.Name <> "" Then
.AddItem Sh.Name

End If

Next
End With

End Sub
 
J

Jim Rech

To block direct entry into the combo box just change its Style to
fmStyleDropDownList.

RE holding its value you might see how this works:

Dim ItemIndex As Integer

Private Sub ComboBox1_Change()
If ComboBox1.ListIndex >= 0 Then
ItemIndex = ComboBox1.ListIndex
End If
End Sub

Private Sub ComboBox1_DropButtonClick()
Dim Sh As Worksheet
With ComboBox1
.Clear
For Each Sh In ActiveWorkbook.Sheets
If Sh.Name <> "" Then
.AddItem Sh.Name
End If
Next
.ListIndex = ItemIndex
End With
End Sub


--
Jim
| The code below list all the sheets name of active workbook in drop
| down list. Because of the code line ".CLEAR" I am not able to get
| combobox value. I want that when I select sheet name in drop down
| list that name should appear as combobox text or value. and also how
| can i stop some one to write in combobox as i want if some one write
| in combobox the msgbox should appear saying "Select from drop down
| list". Please can any friend solve my these queries about combobox.
| Thanks
|
| Private Sub ComboBox1_DropButtonClick()
| Dim Sh As Worksheet
| With ComboBox1
| .CLEAR
| For Each Sh In ActiveWorkbook.Sheets
| If Sh.Name <> "" Then
| .AddItem Sh.Name
|
| End If
|
| Next
| End With
|
| End Sub
 
K

K

To block direct entry into the combo box just change its Style to
fmStyleDropDownList.

RE holding its value you might see how this works:

Dim ItemIndex As Integer

Private Sub ComboBox1_Change()
    If ComboBox1.ListIndex >= 0 Then
        ItemIndex = ComboBox1.ListIndex
    End If
End Sub

Private Sub ComboBox1_DropButtonClick()
    Dim Sh As Worksheet
    With ComboBox1
        .Clear
          For Each Sh In ActiveWorkbook.Sheets
              If Sh.Name <> "" Then
                .AddItem Sh.Name
              End If
          Next
          .ListIndex = ItemIndex
    End With
End Sub

--

| The code below list all the sheets name of active workbook in drop
| down list.  Because of the code line ".CLEAR" I am not able to get
| combobox value.  I want that when I select sheet name in drop down
| list that name should appear as combobox text or value.  and also how
| can i stop some one to write in combobox as i want if some one write
| in combobox the msgbox should appear saying "Select from drop down
| list".  Please can any friend solve my these queries about combobox.
| Thanks
|
| Private Sub ComboBox1_DropButtonClick()
| Dim Sh As Worksheet
| With ComboBox1
|    .CLEAR
|      For Each Sh In ActiveWorkbook.Sheets
|          If Sh.Name <> "" Then
|            .AddItem Sh.Name
|
|          End If
|
|      Next
| End With
|
| End Sub

Thanks lot Jim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top