Textboxen in Zeile wenn nicht leer
08.04.2021 13:06:48
Tim
ich habe auf einer Userform, 8 Textboxen, deren Inhalt ich in ein Tabellenblatt schreiben möchte. Der Inhalt aus den Textboxen soll ein eine Spalte untereinander geschrieben werden, das funktioniert. Meine Herausforderung besteht darin, dass ich nur die Einträge der gefüllten Textboxen in die Tabelle schreiben möchte, leere Textboxen sollen ignoriert werden. Zudem sind die Textboxen spezifisch benannt ("Name").
Könnt ihr mir bitte bei der Umsetzung behilflich sein?
Sub Zahlen()
Dim lngZeile As Long,Zahlen As Worksheet
Dim ctrl As Control
With Application
.ScreenUpdating = False
.EnableEvents = False
.Calculation = xlCalculationManual
End With
Set Zahlen = ThisWorkbook.Worksheets("Zahlen")
Zahlen.Range("A2:E65536").ClearContents
lngZeile = Zahlen.Cells(Zahlen.Rows.Count, 1).End(xlUp).Row
For Each ctrl In UserForm6.Controls
If TypeName(ctrl) = "TextBox" Then
If ctrl.Text "" Then
With Zahlen
.Cells(lngZeile + 1, 2) = UserForm6.Zahl1.Text 'Anzahl
.Cells(lngZeile + 1, 1) = "Test1" 'Wer
.Cells(lngZeile + 1, 3) = Date
.Cells(lngZeile + 1, 4) = VBA.Environ("Username")
.Cells(lngZeile + 2, 2) = UserForm6.Zahl2.Text 'Anzahl
.Cells(lngZeile + 2, 1) = "Test2" 'Wer
End With
End If
End If
Next ctrl
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = xlCalculationAutomatic
End With
Unload UserForm6
End Sub