为什么这个VBA公式不会改变工作表的价值?

我想询问下面创build的vba代码。 在我testing之后,它的表格值不变。 如何解决这个代码,以便当我input的值可以在工作表中更新?

Private Sub cmdupdate_click() Application.ScreenUpdating = False Dim noM As Integer 'warning If txtName.Value = "" Then MsgBox "Insert Name.", vbExclamation txtName.SetFocus Exit Sub End If If Me.cmbslno.Value = "" Then MsgBox "No Number!!!", vbExclamation, "Number" Exit Sub End If noM = Me.cmbslno.Value Sheets("data").Select Dim bre As Double Dim msg As String Dim org As String bre = Me.cmbslno.Value bre = bre + 1 Rows(bre).Select Cells(bre, 2) = Me.txtName.Value Cells(bre, 3) = Me.txtPanggilan.Value Cells(bre, 4) = Me.txtNis.Value Cells(bre, 5) = Me.txtNisn.Value Cells(bre, 6) = Me.txtTtl.Value Cells(bre, 7) = Me.CmbJk.Value Cells(bre, 8) = Me.CmbAgama.Value Cells(bre, 9) = Me.txtSAwal.Value Cells(bre, 10) = Me.txtASiswa.Value Cells(bre, 11) = Me.txtAyah.Value Cells(bre, 12) = Me.txtIbu.Value Cells(bre, 13) = Me.txtPAyah.Value Cells(bre, 14) = Me.txtPIbu.Value Cells(bre, 15) = Me.txtJln.Value Cells(bre, 16) = Me.txtDesa.Value Cells(bre, 17) = Me.txtKec.Value Cells(bre, 18) = Me.txtKab.Value Cells(bre, 19) = Me.txtPro.Value Cells(bre, 20) = Me.txtHp.Value Cells(bre, 21) = Me.txtWali.Value Cells(bre, 22) = Me.txtPWali.Value Cells(bre, 23) = Me.txtAWali.Value Cells(bre, 36) = Me.txtFoto.Value bre = bre - 1 msg = "Number " & bre & ". For " & txtName.Value & " Updating . Continue?" Unload Me org = MsgBox(msg, vbYesNo, "Confirm") If org = vbYes Then Me.FormData.Show Else Sheets("Data").Select End If Application.ScreenUpdating = True End Sub 

谢谢,希望能解决

请参阅您的更新代码。 我认为这个问题是遗漏的。单元格赋值语句中的值属性。 我也纠正了其他一些小问题,请看评论。

 Private Sub cmdupdate_click() 'warning If Me.txtName.Value = "" Then MsgBox "Please insert name.", vbExclamation Me.txtName.SetFocus 'added Me for consistency Exit Sub End If If Me.cmbslno.Value = "" Then MsgBox "Please enter number.", vbExclamation 'stopped yelling at the user Me.cmbslno.SetFocus ' added - the same behaviour as previous one Exit Sub End If Application.ScreenUpdating = False 'moved here, otherwise above Exit Sub keeps False Dim noM As Integer 'moved from top, we don't need it earlier noM = Val(Me.cmbslno.Value) Sheets("data").Select Dim bre As Integer ' changed from Double to Integer Dim msg As String Dim org As String bre = Me.cmbslno.Value bre = noM + 1 Rows(bre).Select Cells(bre, 2).Value = Me.txtName.Value Cells(bre, 3).Value = Me.txtPanggilan.Value Cells(bre, 4).Value = Me.txtNis.Value Cells(bre, 5).Value = Me.txtNisn.Value Cells(bre, 6).Value = Me.txtTtl.Value Cells(bre, 7).Value = Me.CmbJk.Value Cells(bre, 8).Value = Me.CmbAgama.Value Cells(bre, 9).Value = Me.txtSAwal.Value Cells(bre, 10).Value = Me.txtASiswa.Value Cells(bre, 11).Value = Me.txtAyah.Value Cells(bre, 12).Value = Me.txtIbu.Value Cells(bre, 13).Value = Me.txtPAyah.Value Cells(bre, 14).Value = Me.txtPIbu.Value Cells(bre, 15).Value = Me.txtJln.Value Cells(bre, 16).Value = Me.txtDesa.Value Cells(bre, 17).Value = Me.txtKec.Value Cells(bre, 18).Value = Me.txtKab.Value Cells(bre, 19).Value = Me.txtPro.Value Cells(bre, 20).Value = Me.txtHp.Value Cells(bre, 21).Value = Me.txtWali.Value Cells(bre, 22).Value = Me.txtPWali.Value Cells(bre, 23).Value = Me.txtAWali.Value Cells(bre, 36).Value = Me.txtFoto.Value msg = "Number " & noM & ". For " & txtName.Value & " Updating. Continue?" Unload Me org = MsgBox(msg, vbYesNo, "Confirm") If org = vbYes Then Me.FormData.Show Else Sheets("Data").Select End If Application.ScreenUpdating = True End Sub