2019年8月3日 星期六

EXCEL + VBA for Data Entry

程式碼2 
 
Private Sub CommandAdd_Click()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Sheet1")
Dim n As Long
n = sh.Range("A" & Application.Rows.Count).End(xlUp).Row

  If VBA.IsNumeric(Me.TextBox.Value) = False Then
     MsgBox "Number only"
     Exit Sub
  End If
  
  If Me.Object.Value = "" Then
     MsgBox "information"
     Exit Sub
  End If
  
  If Me.CheckBox1.Value = True/False And Me.CheckBox2.Value = True/False And Me.CheckBox3.Value = True/False Then
       MsgBox "information"
     Exit Sub
  End If
  
  sh.Range("A" & n+1).Value = Me.TextBox.Value

  If Me.OptionButton1.Value = True Then sh.Range("C" & n+1).Value = "Man"
  If Me.OptionButton2.Value = True Then sh.Range("C" & n+1).Value = "Woman"

  If Me.CheckBox1.Value = True Then sh.Range("D" & n+1).Value = "X"
  If Me.CheckBox2.Value = True Then sh.Range("D" & n+1).Value = "Y"
  If Me.CheckBox3.Value = True Then sh.Range("D" & n+1).Value = "X"

  sh.Range("E" & n+1).Value = Me.ComboBox2.Value

  If Application.WorksheetFunction.CountIf(sh.Range("A:A"), Me.TextBox1.Value) > 0 Then
    MsgBox "already exist", vbCritical
    Exit Sub
  End If
   
End Sub

= = = = = = = = = =

Private Sub CommandClear_Click()
Me.object.Value = "" or False

End Sub

= = = = = = = = = =

Private Sub UserForm_Activate()
  With Me.ComboBox2
       .Clear
       .AddItem ""
  End With

End Sub

沒有留言:

張貼留言

成對樣本T檢定

鋼鐵人的10套裝甲在接受神盾局調整前後,攻擊指數有所變動,請問神盾局的調整是否對鋼鐵人的裝甲有所幫助?