Clever-Excel-Forum

Normale Version: Leere TextBox bei der Ausagbe zulassen
Du siehst gerade eine vereinfachte Darstellung unserer Inhalte. Normale Ansicht mit richtiger Formatierung.
Hey Excel Profis,

folgende Herausforderung: Ich habe ein Formular mit TextBoxen erstellt. Allerdings ist nicht immer ein Eintrag in einer beliebigen TextBox erforderlich. Bei der Übernahme in die Exceltabelle meckert er dann rum, wenn eine oder mehrere TextBoxen leer sind. Wie und an welcher Stelle schreibe ich den Code so um, dass leere TextBoxen akzeptiert werden?
Besten Dank schon mal im Voraus ;)
Stefan
Code:
Option Explicit

Private Sub CommandButton1_Fertig_Click()

'Erste freie Zeile ausfindig machen
Dim last As Integer
last = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row + 1

'Projektnummer
Cells(last, 1).Value = TextBox_Projektnr.Value * 1

'Straße
Cells(last, 2).Value = TextBox_Straße

'Hs.Nr.
Cells(last, 3).Value = TextBox_Hausnummer.Value * 1

'PLZ
Cells(last, 4).Value = TextBox_PLZ.Value * 1

'Ort/Bezirk
Cells(last, 5).Value = TextBox_OrtBezirk

'WE
Cells(last, 6).Value = TextBox_WE1
Cells(last, 8).Value = TextBox_WE2
Cells(last, 10).Value = TextBox_WE3
Cells(last, 12).Value = TextBox_WE4

'TD
Cells(last, 7).Value = TextBox_TD1.Value * 1
Cells(last, 9).Value = TextBox_TD2.Value * 1
Cells(last, 11).Value = TextBox_TD3.Value * 1
Cells(last, 13).Value = TextBox_TD4.Value * 1

End Sub

Private Sub CommandButton2_Schließen_Click()

Unload Me

End Sub


Private Sub UserForm_Initialize()

'Projektnummer
TextBox_Projektnr = ""

'Straße
TextBox_Straße = ""

'Hs.Nr.
TextBox_Hausnummer = ""

'PLZ
TextBox_PLZ = ""

'Ort/Bezirk
TextBox_OrtBezirk = ""

'WE
TextBox_WE1 = ""
TextBox_WE2 = ""
TextBox_WE3 = ""
TextBox_WE4 = ""

'TD
TextBox_TD1 = ""
TextBox_TD2 = ""
TextBox_TD3 = ""
TextBox_TD4 = ""


End Sub
Hallo Stefan,

bei allen Übergaben mit Berechnungen muss mit If TextBox <> "" Then ... eine bedingte Ausführung gemacht werden.

Gruß Uwe
Hallo Uwe,

vielen Dank für den Tipp. Ich hab das jetzt mal so gemacht...:
Code:
Option Explicit

Private Sub CommandButton1_Fertig_Click()

'Erste freie Zeile ausfindig machen
Dim last As Integer
last = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row + 1

'Projektnummer
Cells(last, 1).Value = IIf(TextBox_Projektnr <> "", TextBox_Projektnr.Value, "0") * 1

'Straße
Cells(last, 2).Value = IIf(TextBox_Straße <> "", TextBox_Straße.Value, "keine Eingabe")

'Hs.Nr.
Cells(last, 3).Value = IIf(TextBox_Hausnummer <> "", TextBox_Hausnummer.Value, "0") * 1

.
.
.
.
etc...
Das funktioniert so schon ganz gut, nur wäre mit eine tatsächlich leer Zelle lieber. Was muss ich eingeben, damit das funktioniert? und nicht die "0" oder "keine Eingabe" da steht... Huh

Grüße Stefan
Hallo Stefan,

mache es so wie ich es vorschlug! Wink
Oder dann
Cells(last, 1).Value = IIf(TextBox_Projektnr <> "", TextBox_Projektnr.Value * 1, "")

Gruß Uwe
GuMo Uwe,

vielen Dank! es klappt. Mega cool!! nice WE
Gruß Stefan