Private Sub CommandButton1_Click() Dim i As Long For i = 1 To 2 If Me.Controls("TextBox" & i).Text = "" Then MsgBox Me.Controls("Label" & i).Caption & "不得为空!": Exit Sub Next i If TextBox4.Text = "" Then MsgBox "单价不得为空!": Exit Sub i = Application.WorksheetFunction.CountA(Columns("a:a")) + 2 Cells(i, 1) = Format(TextBox1.Text, "0") Cells(i, 2) = TextBox2 Cells(i, 3) = TextBox3 Cells(i, 4) = Format(TextBox4.Text, "0.00") Cells(i, 5) = TextBox5 Cells(i, 6) = TextBox6 Cells(i, 7) = Format(DTPicker1.Value, "yyyy-mm-dd") Cells(i, 8) = TextBox8 TextBox1 = TextBox1 + 1 TextBox2 = "" TextBox3 = "" TextBox4 = "" TextBox5 = "" TextBox6 = "" TextBox8 = "" 'TextBox7 = "" End Sub Private Sub CommandButton2_Click() Unload Me End Sub Private Sub DTPicker1_CallbackKeyDown(ByVal KeyCode As Integer, ByVal Shift As Integer, ByVal CallbackField As String, CallbackDate As Date) End Sub Private Sub UserForm_Initialize() t = Sheet1.Range("A65536").End(xlUp).Row If t = 2 Then TextBox1.Text = "1" Else TextBox1.Text = Val(Sheet1.Range("A" & t).Value) + 1 End Sub |