office交流网--QQ交流群号

Access培训群:792054000         Excel免费交流群群:686050929          Outlook交流群:221378704    

Word交流群:218156588             PPT交流群:324131555

VBA在列表框ListBox指定行插入数据项目

2019-07-07 11:47:00
zstmtony
原创
9864

VBA在列表框ListBox指定行插入数据项目

Listbox的additm 第2个参数 可指定插入的位置

Option Explicit
Dim A As String
Dim B As Integer
Dim C As Integer
Dim I As Integer


Private Sub CMDADD_Click()
B = InputBox("想添加到第几行?")
C = List1.ListCount
If B < 0 Or B > C + 1 Then
InputBox ("请不要超过现有行数,请重新输入")
Else
If Text1.Text = "" Then
MsgBox ("请在文本框中输入内容")
Else
For I = C To B Step -1
List1.List(I) = List1.List(I - 1)
Next I
List1.AddItem Text1.Text, (B - 1)
End If
End If

End Sub

分享