ich füge bei Klicken eines Buttons automatisch eine TextBox und ein Label untereinander in einer UserForm ein. Das funktioniert wie folgt:
Private Sub CommandButton1_Click()
Dim objTextBox As Control
Dim objLabel As Control
Dim x As Long
x = intAnzahl * 20
Set objTextBox = Me.Controls.Add("Forms.TextBox.1", "TextBox" & intAnzahl, Visible)
With objTextBox
.Left = 12.5
.Top = x + 48
.Width = 40
End With
Set objLabel = Me.Controls.Add("Forms.Label.1", "Label" & intAnzahl, Visible)
With objLabel
.Caption = "Test"
.Left = 300
.Top = x + 48
.Width = 40
End With
intAnzahl = intAnzahl + 1
End Sub
Private Sub UserForm_Initialize()
intAnzahl = 1
End Sub
Jetzt möchte ich beim Drücken eines zweiten Buttons die Werte die in der TextBox eingegeben worden sind in eine Excel Tabelle übertragen. Das mache ich wie folgt:Private Sub CommandButton_Einfügen_Click()
Dim last As Long
With Sheets("Datenbank")
last = .Cells(Rows.Count, 2).End(xlUp).Row + 1
.Cells(last, 1).Value = UserForm6.TextBox1
.Cells(last, 2).Value = UserForm6.TextBox2
End With
MsgBox ("Die Daten wurden erfolgreich in die Datenbank eingegeben!")
Unload UserForm1
Unload UserForm6
ActiveWorkbook.Save
End Sub
Allerdings tut sich bei diesem Schritt leider gar nichts bei mir. Sieht einer meinen Fehler warum die Daten nicht in die jeweiligen Felder in die Tabelle eingetragen werden? Betse Grüße,
Steph