在这个问题中,我所做的编码似乎不工作,当我运行vba并单击删除按钮什么也没发生。我不知道它的错误,因为它没有显示任何错误调试。
Private Sub cmdDelete_Click()
Dim i As Long
Dim selectedRows() As Long
Dim count As Long
Dim currentListBox As MSForms.listBox
Dim currentPage As Long
' Determine the active ListBox on the current page
currentPage = MultiPage1.Value
' Identify the active ListBox based on the current page
Select Case currentPage
Case 0
Set currentListBox = ListBox1
Case 1
Set currentListBox = ListBox2
Case 2
Set currentListBox = ListBox3
Case 3
Set currentListBox = ListBox4
Case Else
' Handle any other cases if needed
End Select
' Check if a ListBox was identified
If currentListBox Is Nothing Then
MsgBox "Please ensure a ListBox is selected.", vbExclamation
Exit Sub
End If
' Determine the selected rows in the identified ListBox
count = 0
For i = 0 To currentListBox.ListCount - 1
If currentListBox.Selected(i) Then
ReDim Preserve selectedRows(count)
selectedRows(count) = i
count = count + 1
End If
Next i
' Delete the selected rows in reverse order
For i = UBound(selectedRows) To LBound(selectedRows) Step -1
' Use the current ListBox's Tag property to determine which ListBox to delete from
Select Case currentListBox.Tag
Case "1"
' Delete rows from ListBox1 on Page 1
MultiPage1.Pages(0).ListBox1.RemoveItem selectedRows(i)
Case "2"
' Delete rows from ListBox2 on Page 2
MultiPage1.Pages(1).ListBox2.RemoveItem selectedRows(i)
Case "3"
' Delete rows from ListBox3 on Page 3
MultiPage1.Pages(2).ListBox3.RemoveItem selectedRows(i)
Case "4"
' Delete rows from ListBox4 on Page 4
MultiPage1.Pages(3).ListBox4.RemoveItem selectedRows(i)
End Select
Next i
End Sub
字符串
这是我做的编码,并坚持这个删除按钮。
2条答案
按热度按时间kognpnkq1#
你没有回答澄清问题.所以,我上面的改编代码能够删除活动列表框或所有列表框中的选定行(根据
boolAllLstBoxes
布尔变量):字符串
上面的代码用于
ReDim Preserve
的方式在内存处理方面更好。如果你需要一段代码,能够删除行(只)在列表框中的活动页面,上述代码可以大大简化。
请在测试后发送一些反馈。
juzqafwq2#
你的措辞对我来说不是很清楚
一个猜测是,你可以简单地说:
字符串