为什么userform的数据总是去同一行?

时间:2017-08-16 11:09:51

标签: vba excel-vba excel

我不知道自己做错了什么,当我在用户表单中输入数据时,所有信息都显示出来,但是它总是在同一行,它不会转到下一个空行。我试图将数据输入我的excel文件,并继续将信息添加到下一个空行。

Private Sub CommandButton1_Click()

    Dim emptyRow As Long

    'Make Sheet1 active
    Sheet1.Activate

    'Determine emptyRow
    emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1

    'values need to be enter in order to move on
    If ComboBox1.Value = "" Then
        Cancel = 1
        MsgBox "Please enter the part line "
        ComboBox1.SetFocus
        Exit Sub
    End If

    If ComboBox4.Value = "" Then
        Cancel = 1
        MsgBox "Please enter a part description"
        ComboBox4.SetFocus
        Exit Sub
    End If

    If TextBox3.Value = "" Then
        Cancel = 1
        MsgBox "Please enter a part quantity"
        TextBox3.SetFocus
        Exit Sub
    End If

    If ComboBox2.Value = "" Then
        Cancel = 1
        MsgBox "Please enter a part finish"
        ComboBox2.SetFocus
        Exit Sub
    End If

    'Transfer information

    Cells(emptyRow, 1).Value = ComboBox1.Value
    Cells(emptyRow, 2).Value = TextBox1.Value
    Cells(emptyRow, 3).Value = ComboBox4.Value
    Cells(emptyRow, 4).Value = TextBox3.Value
    Cells(emptyRow, 5).Value = ComboBox2.Value
    Cells(emptyRow, 6).Value = DTPicker1.Value


    ComboBox1.Value = Null
    ComboBox4.Value = Null
    TextBox3.Value = Null
    ComboBox2.Value = Null

End Sub

1 个答案:

答案 0 :(得分:0)

你想要得到这样的下一个空行:

Campaign