我很难过,我尝试了以下内容,在我的生活中,我无法弄清楚这一点......需要在excel vba表单上使用列表框上的命令按钮。
在加载时使表单不正常.....它加载正常
Sub UserForm_Initialize()
UserForm1.LbNumbers.RowSource = "Sheet2!A1:A3"End Sub
项目显示在列表框中
我在列表框下面有一个命令按钮来选择所有代码
Sub CbSelectall_Click()
For i = 0 To LbNumbers.ListCount - 1
LbNumbers.Selected(i) = True
Next i
End Sub
如果我点击按钮,它会跳转到最后一行,但它不会选择列表框中的所有数字。有人可以告诉我如何纠正它以选择列表框中的所有数字。谢谢
答案 0 :(得分:0)
Private Sub lbTraderId_Change() If ResetListBox(lbTraderId) Then Exit Sub ElseIf lbTraderId.Selected(0) Then For i = 1 To lbTraderId.ListCount - 1 If lbTraderId.Selected(i) = False Then lbTraderId.Selected(i) = True End If Next i ElseIf lbTraderId.Selected(0) = False Then For i = 1 To lbTraderId.ListCount - 1 If lbTraderId.Selected(i) = True Then lbTraderId.Selected(i) = False End If Next i End If End Sub Private Function ResetListBox(lbx As MSForms.ListBox) As Boolean Dim x As Long Static bExit As Boolean If Not bExit Then x = lbx.ListIndex If x >= 0 And Not lbx Is Me.lbTraderId Then bExit = True lbx.Selected(x) = Not lbx.Selected(x) bExit = False ResetListBox = True End If End If End Function