office交流網--QQ交流群號

Access培訓群:792054000         Excel免費交流群群:686050929          Outlook交流群:221378704    

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

Listbox的相關VBA代碼

2019-11-13 14:00:00
zstmtony
轉貼
311
Private Sub btnUpdate_Click()
    Dim values(3)
    Dim u As Long
    u = ListBox1.ListIndex
    If u <> -1 Then
            values(0) = TextBox1.Value
            values(1) = TextBox2.Value
            values(2) = TextBox3.Value
            values(3) = TextBox4.Value

         With ListBox1
         .RemoveItem u
         .AddItem values(0), u
            .List(u, 1) = values(1)
            .List(u, 2) = values(2)
            .List(u, 3) = values(3)
        End With
    End If
End Sub

Private Sub ListBox1_Click()
    Dim i As Long
    With Me
        i = .ListBox1.ListIndex
        .ListBox1.Selected(i) = True
        .TextBox1.Value = .ListBox1.Column(0, i)
        .TextBox2.Value = .ListBox1.Column(1, i)
        .TextBox3.Value = .ListBox1.Column(2, i)
        .TextBox4.Value = .ListBox1.Column(3, i)
    End With
End Sub
分享