Saladsamurai
10-13-2009, 09:35 AM
Hi all. I am just messing around with VBA today trying to learn some new stuff here.
I am onto ComboBoxes. I have placed one in a worksheet using the Controls
toolbar.
I have copied this lame code that I found online just to get the idea of how it works.
Option Explicit
Private Sub ComboBox1_Change()
Select Case ComboBox1.Text
Case "Dogs"
MsgBox "Dogs"
Case "Cats"
MsgBox "Cat"
Case "Mice"
MsgBox "Mice"
Case Else
End Select
End Sub
Private Sub Worksheet_Activate()
ComboBox1.Clear
ComboBox1.AddItem "Dogs"
ComboBox1.AddItem "Cats"
ComboBox1.AddItem "Mice"
ComboBox1.Text = ComboBox1.List(0)
End Sub
What does the bold line instruct Excel to do?
I get that it is a WorkSheet Event code in which it clears (unpopulates)
alll of the drop-down options. Then it repopulates them with the AddItem thingy. But what does "ComboBox1.Text = ComboBox1.List(0)" do?
Thanks!
I am onto ComboBoxes. I have placed one in a worksheet using the Controls
toolbar.
I have copied this lame code that I found online just to get the idea of how it works.
Option Explicit
Private Sub ComboBox1_Change()
Select Case ComboBox1.Text
Case "Dogs"
MsgBox "Dogs"
Case "Cats"
MsgBox "Cat"
Case "Mice"
MsgBox "Mice"
Case Else
End Select
End Sub
Private Sub Worksheet_Activate()
ComboBox1.Clear
ComboBox1.AddItem "Dogs"
ComboBox1.AddItem "Cats"
ComboBox1.AddItem "Mice"
ComboBox1.Text = ComboBox1.List(0)
End Sub
What does the bold line instruct Excel to do?
I get that it is a WorkSheet Event code in which it clears (unpopulates)
alll of the drop-down options. Then it repopulates them with the AddItem thingy. But what does "ComboBox1.Text = ComboBox1.List(0)" do?
Thanks!