2017-08-16 1 views
0

Ich weiß nicht, was ich falsch mache, wenn ich die Daten in das Benutzerformular eingabe alle Informationen erscheinen, aber es ist immer in der gleichen Zeile es geht nicht in die nächste leere Zeile. Ich versuche, die Daten in meine Excel-Datei einzugeben und die Informationen zur nächsten leeren Zeile hinzuzufügen.warum die Daten der Benutzerform immer in die gleiche Zeile?

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

Versuchen mit "yourworksheet.Cells (ActiveSheet.Rows.Count, 1) .End (xlUp) .Row" statt of WorksheetFunction.CountA (Bereich ("A: A")) + 1 –

Antwort

0

Sie die nächste leere Zeile wie diese stattdessen erhalten möchten:

emptyRow = ActiveSheet.Cells(ActiveSheet.Rows.Count, 1).End(xlUp).Row 
+0

Ich versuche das und jetzt werden die Daten die ganze Zeit in der Zeile der letzten Zeile und nicht auf der leeren Zeile, die sich auf der Unterseite befindet, platziert. – genaro

Verwandte Themen