按下编辑按钮时Excel用户表单显示错误信息

im9ewurl  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(100)


的数据
我正在做一个个人项目的学习目的.我不能弄清楚为什么错误的信息得到填充在我的用户表单,当我选择编辑按钮.它迫使我重新输入信息再次编辑该行.我做错了什么,让信息填充错误的文本框?

Private Sub cmdEdit_Click()

    If Selected_List = 0 Then
    
            MsgBox "NO row is selected.", vbOKOnly + vbInformation, "Edit"
            
            Exit Sub
    
    End If

    'Code to update the value to respective controls
    
    Me.txtRowNumber.Value = Application.WorksheetFunction.Match(Me.lstDatabase.List(Me.lstDatabase.ListIndex, 0), _
    ThisWorkbook.Sheets("Database").Range("A:A"), 0)
    
    Me.txtJCN.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 1)
    
    Me.cmbLocation.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 2)

    Me.cmbStatus.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 3)
    
    Me.txttaskname.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 4)
    
    Me.txtdateopened.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 5)
    
    Me.txtproblem.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 6)
    
    Me.txtfixaction.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 8)
    
    MsgBox "Please make the required changes and clock on 'SAVE' button to update.", vbOKOnly + vbInformation, "Edit"
    

End Sub

字符串
我试着重新组织me.txt来排列顺序。那不起作用。我对JavaScript代码很有经验。

ffscu2ro

ffscu2ro1#

第一列为0,即List(i,0)

Private Sub cmdEdit_Click()

    Dim rngA As Range, i As Long
    Set rngA = ThisWorkbook.Sheets("Database").Range("A:A")

    With Me.lstDatabase
        i = .ListIndex
        If i < 0 Then
            MsgBox "No row is selected.", vbExclamation, "Edit"
            Exit Sub
        End If
        
        'Code to update the value to respective controls
        Me.txtRowNumber.Value = Application.Match(.List(i, 0), rngA, 0)
        Me.txtJCN.Value = .List(i, 0)
        Me.cmbLocation.Value = .List(i, 1)
        Me.cmbStatus.Value = .List(i, 2)
        Me.txttaskname.Value = .List(i, 3)
        Me.txtdateopened.Value = .List(i, 4)
        Me.txtproblem.Value = .List(i, 5)
        Me.txtfixaction.Value = .List(i, 7)
    End With
    '
    MsgBox "Please make the required changes and " & _
           "clock on 'SAVE' button to update.", vbOKOnly + vbInformation, "Edit"
    
End Sub

字符串

相关问题