Listbox

1 '添加条目 RowSource
2 Private Sub UserForm_Initialize()
3     Range("a1:a10").Name = "DataSource"
4     Me.lbx.RowSource = "DataSource" 'Rowsourse = string
5 End Sub
 1 '添加条目 Additem
 2 Private Sub UserForm_Initialize()
 3     Dim I&
 4     With Me.lbx
 5         .RowSource = "" '非空出现拒绝使用此权限
 6         For I = 1 To 10
 7             .AddItem Cells(I, 1).Value, I - 1 ' AddItem[ item [, varIndex ]] 索引从0开始,-1为未选中
 8         Next I
 9     End With
10 End Sub
1 '添加条目 List
2 Private Sub UserForm_Initialize()
3     Me.lbx.List = Application.WorksheetFunction.Transpose(Range("a1:a10").Value)
4 End Sub
1 '单选
2 Private Sub cmdOk_Click()
3     If Me.lbx.ListIndex <> -1 Then
4         MsgBox "选中 " & Me.lbx.Value, vbInformation
5     Else
6         MsgBox "未选中"
7     End If
8  Unload Me
9 End Sub

 

posted @ 2019-06-24 08:17  易塞尔工作室  阅读(483)  评论(0编辑  收藏  举报