我正在寻找一种方法让我的用户表单上的组合框具有默认值为no或类似"从下面选择"。
尝试了各种谷歌建议,但如果它是代码的第一次迭代,或者更糟糕的是之前选择的值,那么我的组合框中显示的值是空白的。
代码低于......
' Begin Code
Private Sub UserForm_Initialize()
Dim RngTags As Range, RngNames As Range, i As Long
ComboBox1.Value = "SomeText"
'Set rng1 = Sheets("Admin").Range("deptrange2")
Set rng1 = Range("ALLDEPT")
With ComboBox1
.ColumnCount = 1
.Style = fmStyleDropDownList
.TextAlign = fmTextAlignLeft
.BoundColumn = 1
For i = 1 To rng1.Count
.AddItem rng1(i).Value
.List(.ListCount - 1, 1) = rng1(i).Value
Next i
End With
End Sub
' Puts the value chosen from the list on admin f6
Private Sub ComboBox1_Change()
Sheets("Admin").Range("f8").Value = ComboBox1.Value
Call myUnLoad
End Sub
' Gets rid of userform
Sub myUnLoad()
UserForm1.Hide
End Sub
' End code
由于
安德鲁
答案 0 :(得分:1)
添加值后,需要将ListIndex设置为0。
Combobox1.ListIndex=0