![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Guest
Posts: n/a
|
How do you reference the text or values in a List Box. i.e. suppose I want to unhide a sheet if a box is checked or highlighted in the list box, how do I reference the value and what function do I use (i.e. ListBox_Change, ListBox_Click, etc...).
For a combo box I would write Private Sub ComboBox_Change() If ComboBox = "Argentina" Then Sheets("Argentina").Visible = True End If End Sub How do I do this same thing with a list box. I want to be able to select multiple countries and unhide the appropriate sheets. Thanks |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Each value/text in a listbox is automatically assigned a number
The first value is 0, second 1, etc. Use this for what you are trying to do. Private Sub ListBox_Change() If SolutionBox.Selected(0) = True Then Sheets("Argentina").Visible = True Else Sheets("Argentina").Visible = False End If End Sub |
|
|
|
#3 | |
|
Guest
Posts: n/a
|
Quote:
Code:
Private Sub CommandButton1_Click()
Dim intI As Integer
For intI = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(intI) Then
Sheets(ListBox1.List(intI)).Visible = True
End If
Next intI
End Sub
I hope this helps, Russell |
|
|
|
|
#4 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Portland, OR USA
Posts: 1,374
|
Sorry, the last message was from me.
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|