VB list删除指定的几行

2025-02-27 00:15:46
推荐回答(2个)
回答1:

楼主参考一下:

Private Sub Command1_Click()
   Dim B As Long, E As Long
   Dim N As Long
   Dim i As Long
   
   '第4行到第12行,ListIndex就是3到11
   B = Val(Text1) - 1   '起始行
   E = Val(Text2) - 1   '结束行
   N = List1.ListCount - 1
   If (N > E) Then N = E
   '先删除指定范围内的行
   For i = N To B Step -1
      List1.RemoveItem i
   Next
   '再移除空行
   For i = List1.ListCount - 1 To 0 Step -1
      If (List1.List(i) = "") Then List1.RemoveItem i
      '如果全是空格的行也算,就改为:
      'If (Trim$(List1.List(i)) = "") Then List1.RemoveItem i
   Next
End Sub

回答2:

for i=val(text2) to val(text1) step -1
list1.RemoveItem i
next