我有一个用户窗体,可以在Excel的表中添加信息,结果显示在列表框中。
问题是,当我想修改列表框中的信息时,它提示我“未选择任何行”。
这是“编辑”按钮中的代码:
If Selected_List = 0 Then
MsgBox "No row is selected.", vbOKOnly + vbInformation, "edit"
Exit Sub
End If
Me.txtRowNumber2.Value = Me.ListBox2.List(Me.ListBox2.ListIndex, 0) + 1
'Assign the value
adminpanel.TextBox9.Value = Me.ListBox2.List(Me.ListBox2.ListIndex, 1)
adminpanel.TextBox10.Value = Me.ListBox2.List(Me.ListBox2.ListIndex, 2)
adminpanel.TextBox11.Value = Me.ListBox2.List(Me.ListBox2.ListIndex, 3)
adminpanel.TextBox12.Value = Me.ListBox2.List(Me.ListBox2.ListIndex, 4)
adminpanel.TextBox13.Value = Me.ListBox2.List(Me.ListBox2.ListIndex, 5)
adminpanel.TextBox14.Value = Me.ListBox2.List(Me.ListBox2.ListIndex, 6)
adminpanel.TextBox15.Value = Me.ListBox2.List(Me.ListBox2.ListIndex, 7)
adminpanel.CommandButton28.Caption = "edit"
MsgBox "Please make the required changes and click on update to save."
答案 0 :(得分:0)
我找到了要替换的解决方案
如果Selected_List = 0,那么
MsgBox "No row is selected.", vbOKOnly + vbInformation, "edit"
Exit Sub
End If
使用
If ListBox2.ListIndex = -1 Then
MsgBox "There are no items selected to delete"
End If
我很高兴与您分享解决方案 谢谢