Clever-Excel-Forum

Normale Version: Textboxen als Zahl in Tabelle übergeben
Du siehst gerade eine vereinfachte Darstellung unserer Inhalte. Normale Ansicht mit richtiger Formatierung.
Seiten: 1 2
Hallo,

ich habe folgenden Code.
Code:
Private Sub Userform_Initialize()
MsgBox "Es müssen immer kleine Teige eingegeben werden"

TextBox3 = Format$(Date, "dd.mm.yyyy")

End Sub

'Button:  Übernehmen
Private Sub CommandButton1_Click()
Dim lz1 As Long   'LastZell in Tabelle1
 On Error GoTo Fehler
 lz1 = Cells(Rows.Count, 1).End(xlUp).Row + 1
 'Parameter
 Cells(lz1, 1) = TextBox1.Text
 Cells(lz1, 2) = TextBox2.Text
 Cells(lz1, 3) = TextBox3.Text
 Cells(lz1, 4) = TextBoxTT.Text
 Cells(lz1, 5) = TextBoxTRW.Text
 Cells(lz1, 6) = TextBoxTRS.Text
 Cells(lz1, 7) = TextBoxRD.Text
 Cells(lz1, 8) = TextBoxRE.Text
 Cells(lz1, 9) = TextBoxKZL.Text
 Cells(lz1, 10) = TextBoxKZS.Text
 
 'Maische
 Cells(lz1, 11) = TextBoxMAISCHEW.Text
 Cells(lz1, 12) = TextBoxMAISCHERB.Text

 
 'Quellstück
 Cells(lz1, 13) = ComboBoxQS1.Text
 Cells(lz1, 15) = TextBoxQS1.Text
 Cells(lz1, 16) = ComboBoxQS2.Text
 Cells(lz1, 18) = TextBoxQS2.Text
 Cells(lz1, 19) = ComboBoxQS3.Text
 Cells(lz1, 21) = TextBoxQS3.Text
 Cells(lz1, 22) = TextBoxTE.Text
 
 'Bestreuung
 Cells(lz1, 23) = ComboBox_Bestreuung1.Text
 Cells(lz1, 25) = TextBoxBESTREUUNG1.Text
 Cells(lz1, 26) = ComboBox_Bestreuung2.Text
 Cells(lz1, 28) = TextBoxBESTREUUNG2.Text
 Cells(lz1, 29) = ComboBox_Bestreuung3.Text
 Cells(lz1, 31) = TextBoxBESTREUUNG3.Text
 Cells(lz1, 32) = ComboBox_Bestreuung4.Text
 Cells(lz1, 34) = TextBoxBESTREUUNG4.Text
 
 'Rohstoffe
 Cells(lz1, 35) = ComboBoxR1.Text
 Cells(lz1, 37) = TextBoxR1.Text
 Cells(lz1, 38) = ComboBoxR2.Text
 Cells(lz1, 40) = TextBoxR2.Text
 Cells(lz1, 41) = ComboBoxR3.Text
 Cells(lz1, 43) = TextBoxR3.Text
 Cells(lz1, 44) = ComboBoxR4.Text
 Cells(lz1, 46) = TextBoxR4.Text
 Cells(lz1, 47) = ComboBoxR5.Text
 Cells(lz1, 49) = TextBoxR5.Text
 Cells(lz1, 50) = ComboBoxR6.Text
 Cells(lz1, 52) = TextBoxR6.Text
 Cells(lz1, 53) = ComboBoxR7.Text
 Cells(lz1, 55) = TextBoxR7.Text
 Cells(lz1, 56) = ComboBoxR8.Text
 Cells(lz1, 58) = TextBoxR8.Text
 Cells(lz1, 59) = ComboBoxR9.Text
 Cells(lz1, 61) = TextBoxR9.Text
 Cells(lz1, 62) = ComboBoxR10.Text
 Cells(lz1, 64) = TextBoxR10.Text
 Cells(lz1, 65) = ComboBoxR11.Text
 Cells(lz1, 67) = TextBoxR11.Text
 Cells(lz1, 68) = ComboBoxR12.Text
 Cells(lz1, 70) = TextBoxR12.Text
 Cells(lz1, 71) = ComboBoxR13.Text
 Cells(lz1, 73) = TextBoxR13.Text
 Cells(lz1, 74) = ComboBoxR14.Text
 Cells(lz1, 76) = TextBoxR14.Text
 Exit Sub

Fehler:  MsgBox "Eingabe Fehler aufgetreten"
End Sub

'Button:  Abbrechen
Private Sub CommandButton2_Click()
 Unload Me
End Sub
jetzt muss ich das alle Textboxen (außer TextBox1-3) bei der übergabe in die Tabelle als Zahl übergeben werden. wie bekomme ich das hin?


MfG

Sven
Hi

Wenn ich es richtig verstanden habe: 
Versuch mal textbox1.value*1
Ich habe leider nicht die Ahnung von VBA.

Ich will doch TextBox 1-3 So lassen (Wird Text eingetragen)

nur alle anderen sollen als Zahl eingetragen werden.
wo muss ich das hinschreiben
unter meinen Code für jede Textbox?

MFG

Sven
Versuch mal 
Cells(lz1,4) = textboxtt.text



In das hier zu ändern
Cells(lz1,4) = textboxtt.value*1
Dann springt er gleich auf die Fehler Meldung

Zur sicherheit hier der geänderte Code

Code:
Private Sub Userform_Initialize()
MsgBox "Es müssen immer kleine Teige eingegeben werden"

TextBox3 = Format$(Date, "dd.mm.yyyy")

End Sub

'Button:  Übernehmen
Private Sub CommandButton1_Click()
Dim lz1 As Long   'LastZell in Tabelle1
 On Error GoTo Fehler
 lz1 = Cells(Rows.Count, 1).End(xlUp).Row + 1
 'Parameter
 Cells(lz1, 1) = TextBox1.Text
 Cells(lz1, 2) = TextBox2.Text
 Cells(lz1, 3) = TextBox3.Text
 Cells(lz1, 4) = TextBoxTT.Value * 1
 Cells(lz1, 5) = TextBoxTRW.Text
 Cells(lz1, 6) = TextBoxTRS.Text
 Cells(lz1, 7) = TextBoxRD.Text
 Cells(lz1, 8) = TextBoxRE.Text
 Cells(lz1, 9) = TextBoxKZL.Text
 Cells(lz1, 10) = TextBoxKZS.Text
 
 'Maische
 Cells(lz1, 11) = TextBoxMAISCHEW.Text
 Cells(lz1, 12) = TextBoxMAISCHERB.Text

 
 'Quellstück
 Cells(lz1, 13) = ComboBoxQS1.Text
 Cells(lz1, 15) = TextBoxQS1.Text
 Cells(lz1, 16) = ComboBoxQS2.Text
 Cells(lz1, 18) = TextBoxQS2.Text
 Cells(lz1, 19) = ComboBoxQS3.Text
 Cells(lz1, 21) = TextBoxQS3.Text
 Cells(lz1, 22) = TextBoxTE.Text
 
 'Bestreuung
 Cells(lz1, 23) = ComboBox_Bestreuung1.Text
 Cells(lz1, 25) = TextBoxBESTREUUNG1.Text
 Cells(lz1, 26) = ComboBox_Bestreuung2.Text
 Cells(lz1, 28) = TextBoxBESTREUUNG2.Text
 Cells(lz1, 29) = ComboBox_Bestreuung3.Text
 Cells(lz1, 31) = TextBoxBESTREUUNG3.Text
 Cells(lz1, 32) = ComboBox_Bestreuung4.Text
 Cells(lz1, 34) = TextBoxBESTREUUNG4.Text
 
 'Rohstoffe
 Cells(lz1, 35) = ComboBoxR1.Text
 Cells(lz1, 37) = TextBoxR1.Text
 Cells(lz1, 38) = ComboBoxR2.Text
 Cells(lz1, 40) = TextBoxR2.Text
 Cells(lz1, 41) = ComboBoxR3.Text
 Cells(lz1, 43) = TextBoxR3.Text
 Cells(lz1, 44) = ComboBoxR4.Text
 Cells(lz1, 46) = TextBoxR4.Text
 Cells(lz1, 47) = ComboBoxR5.Text
 Cells(lz1, 49) = TextBoxR5.Text
 Cells(lz1, 50) = ComboBoxR6.Text
 Cells(lz1, 52) = TextBoxR6.Text
 Cells(lz1, 53) = ComboBoxR7.Text
 Cells(lz1, 55) = TextBoxR7.Text
 Cells(lz1, 56) = ComboBoxR8.Text
 Cells(lz1, 58) = TextBoxR8.Text
 Cells(lz1, 59) = ComboBoxR9.Text
 Cells(lz1, 61) = TextBoxR9.Text
 Cells(lz1, 62) = ComboBoxR10.Text
 Cells(lz1, 64) = TextBoxR10.Text
 Cells(lz1, 65) = ComboBoxR11.Text
 Cells(lz1, 67) = TextBoxR11.Text
 Cells(lz1, 68) = ComboBoxR12.Text
 Cells(lz1, 70) = TextBoxR12.Text
 Cells(lz1, 71) = ComboBoxR13.Text
 Cells(lz1, 73) = TextBoxR13.Text
 Cells(lz1, 74) = ComboBoxR14.Text
 Cells(lz1, 76) = TextBoxR14.Text
 Exit Sub

Fehler:  MsgBox "Eingabe Fehler aufgetreten"
End Sub

'Button:  Abbrechen
Private Sub CommandButton2_Click()
 Unload Me
End Sub
Hossa, 

Kanns gerade nicht testen, daher nen anderer Ansatz. Schreibe mal folgendes: 

Cells(lz1,4)= cdbl(textboxtt.value)
Klappt Soweit nur nicht bei Dezimal Zahlen.

Ich lade Dir die Datei mal zum testen hoch.

ist es schlimm wenn nicht in jeder Text Box was steht?
Weil Gerade bei TextBoxTT wird nicht immer was drin stehen.

Vielen Dank aber erstmal für deine Überlegungen.
Hi

Versuch es mal so.

Wenn in der Textbox die Zahl mit Punkt   5.32   steht dann.  
If IsNumeric(TextBox1) Then Range("A1").Value2 = Val(TextBox1)


Bei Komma   5,32
If IsNumeric(TextBox2) Then Range("A2").Value2 = TextBox2 * 1

Gruß Elex
Hallo Elex,

wo schreib ich das denn nun wieder hin? und muss ich das für jede TextBox machen?

Es werden kein Zahlen mit Punkt eingegeben


LG Sven
Hi Sven

statt dem
Code:
Cells(lz1, 4) = TextBoxTT.Value * 1

das
Code:
If IsNumeric(TextBoxTT) Then Cells(lz1, 4) = TextBoxTT * 1
 Und das für alle Textboxen wo du Zahlen hast.

Gruß Elex
Seiten: 1 2