2017-06-22 8 views
1

以下に作成したvbaコードについてお問い合わせしたいと思います。テストした後、シートの値は変更されません。このコードを修正して、値Iをシートで更新できるようにする方法?なぜこのvba式はシートの値を変更しないのですか?

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 

あなたの更新されたコードを参照してください、それは

+0

コードをインデントできますか。 – litelite

+0

実際に実行されたかどうかテストするためにブレークポイントを内部に配置しましたか? – litelite

答えて

0

を解決することを願って、ありがとうございます。私は問題がセル値の代入ステートメントで.Valueプロパティがないことにあったと思います。私もいくつかのマイナーな問題を修正しました。コメントを見てください。

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 
+0

Thanx miroxlav ... –

関連する問題