Ich bin VBA Anfänger und brauche noch x Hilfe…
Ich möchte über eine Userform (in Mappe1) existierende Daten aus meiner Mappe2 einlesen und in Mappe1 speichern und über die Userform (in Mappe1) Daten in Mappe2 Eintragen. Was mache ich falsch?
Option Explicit
Private Sub ComboBox1_Click()
If ComboBox1.ListIndex <> 0 Then
TextBox1 = Cells(ComboBox1.ListIndex + 1, 1)
TextBox2 = Cells(ComboBox1.ListIndex + 1, 2)
TextBox3 = Cells(ComboBox1.ListIndex + 1, 3)
Else
TextBox1 = ""
TextBox2 = ""
TextBox3 = ""
End If
End Sub
Private Sub CommandButton1_Click()
If ComboBox1.ListIndex > 0 Then
Rows(ComboBox1.ListIndex + 1).Delete
TextBox1 = ""
TextBox2 = ""
TextBox3 = ""
UserForm_Initialize
End If
End Sub
Private Sub CommandButton2_Click()
Dim xZeile As Long
If TextBox1 = "" Then Exit Sub
If ComboBox1.ListIndex = 0 Then
xZeile = [A65536].End(xlUp).Row + 1
Else
xZeile = ComboBox1.ListIndex + 1
End If
Workbooks("C:\Dokumente und Einstellungen\WP\Desktop\Mappe2.xls").Sheets("Tabelle1").Cells(xZeile, 1) = TextBox1
Workbooks("C:\Dokumente und Einstellungen\WP\Desktop\Mappe2.xls").Sheets("Tabelle1").Cells(xZeile, 2) = TextBox2
Workbooks("C:\Dokumente und Einstellungen\WP\Desktop\Mappe2.xls").Sheets("Tabelle1").Cells(xZeile, 3) = TextBox3
TextBox1 = ""
TextBox2 = ""
TextBox3 = ""
Columns("A:C").Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
UserForm_Initialize
End Sub
Private Sub UserForm_Initialize()
Dim aRow, i As Long
Application.EnableEvents = False
ComboBox1.Clear
aRow = [A65536].End(xlUp).Row
ComboBox1.AddItem "neue Person hinzufügen"
For i = 2 To aRow
ComboBox1.AddItem Cells(i, 1) & ", " & Cells(i, 2)
Next i
ComboBox1.ListIndex = 0
Application.EnableEvents = True
End Sub
Private Sub CommandButton3_Click()
Unload Me
End Sub
|