我创建了一个用于数据输入和更新的表格。除更新按钮外,其他所有功能均适用。
当我单击更新时,仅第一个参数将被更新。例如,假设我要更新B,C,D,E列。
1)单击更新时:仅B列已更新,其他所有内容均未更新。
2)如果我将B的参数屏蔽为注释,那么C列中的单元格将被更新,而不是B,D和E。
3)如果我将C的参数屏蔽为注释,那么D列中的单元格将被更新,而不是其余部分。
下面是我的命令Update和link到当前工作表的代码
Private Sub cmdUpdate_Click()
Dim ws As Worksheet
Dim Ans As String
Set ws = Sheets("TEST")
If cmbSelect = "" Then
MsgBox "The Asset Number TextBox is empty, so no record can be updated in this case." & vbNewLine & _
"Please try again.....", vbExclamation, "Not Found!"
Exit Sub
End If
If WorksheetFunction.CountIf(ws.Columns(1), cmbSelect) = 0 Then
MsgBox "The Asset Number you entered doesn't exist." & vbNewLine & _
"Please try again.....", vbExclamation, "Not Found!"
Exit Sub
End If
Ans = MsgBox("Do you want to update the current record?", vbQuestion + vbYesNo, "Confirm Please!")
If Ans = vbNo Then
MsgBox "You have cancelled the update.", vbExclamation
Exit Sub
End If
r = WorksheetFunction.Match(Val(cmbSelect), ws.Columns(1), 0)
ws.Cells(r, "A") = Me.txtID.Text
Cells(r, "B") = Me.txtClient.Text 'testing different formula, results are the same
Cells(r, "C") = cmbProgram.Text
Cells(r, "D") = Me.TextStartDate.Text
ws.Cells(r, "E") = Me.TextEndDate.Text
ws.Cells(r, "H") = Me.TextLocation.Text
ws.Cells(r, "I") = Me.ComboRegion.Text
ws.Cells(r, "F") = Me.txtMeetOrg.Text
ws.Cells(r, "G") = Me.cmbCategory.Text
ws.Cells(r, "H") = Me.TextLocation.Text
ws.Cells(r, "I") = Me.ComboRegion.Text
ws.Cells(r, "J") = Me.txtOPID.Text
ws.Cells(r, "K") = Me.txtOPOwner.Text
Ws.Cells(r, "L") = Me.txtStatus
ws.Cells(r, "M") = Me.txtFName.Text
ws.Cells(r, "N") = Me.txtPO.Text
ws.Cells(r, "O") = Me.txtFFee.Text
ws.Cells(r, "P") = Me.txtFETransp.Text
ws.Cells(r, "Q") = Me.txtFEHotel.Text
ws.Cells(r, "R") = Me.txtFEMeal.Text
ws.Cells(r, "S") = Me.txtFEMisc.Text
ws.Cells(r, "T") = Me.txtTotalFTE.Text
ws.Cells(r, "U") = Me.txtTotalFE.Text
ws.Cells(r, "V") = Me.txtIE1Name.Text
ws.Cells(r, "W") = Me.txtIE1TE.Text
ws.Cells(r, "X") = Me.txtIE2Name.Text
ws.Cells(r, "Y") = Me.txtIE2TE.Text
ws.Cells(r, "Z") = Me.txtIE3Name.Text
ws.Cells(r, "AA") = Me.txtIE3TE.Text
ws.Cells(r, "AD") = Me.txtParticipant.Text
ws.Cells(r, "AE") = Me.txtResponse.Text
ws.Cells(r, "AF") = Me.txtOverall.Text
ws.Cells(r, "AG") = Me.txtNPS.Text
ws.Cells(r, "AH") = Me.txtImpact.Text
MsgBox "Record has been updated successfully.", vbInformation, "Record Updated!"
End Sub