Problem gelöst mit Power Query Abfrage
Start des Makros hier: Main
*Mit Fragezeichen markierte Zeilen: Ich weiß nicht - was da passiert :)
Aktueller Code für das Userform 1
01 Schließen des Hauptformulars und öffnen Userform1
Private Sub CommandHauptformular_Click()
UserForm1.Hide
Hauptformular.Show
End Sub
02 Neu eingeben (wird aus dem Code entfernt)
Private Sub CommandButton1_Click()
Dim lZeile As Long
With Worksheets("Eingabe")
lZeile = .Cells(.Rows.Count, "A").End(xlUp).Offset(1).Row
.Cells(lZeile, 1) = CStr("Neuer Eintrag Zeile " & lZeile)
ListBox1.AddItem CStr("Neuer Eintrag Zeile " & lZeile)
ListBox1.ListIndex = ListBox1.ListCount - 1
End With
End Sub
03 Löschen des Datensatzes (wird aus dem Code entfernt)
Private Sub CommandButton2_Click()
If ListBox1.ListIndex > -1 Then
Tabelle1.Rows(ListBox1.ListIndex + 3).Delete
Call UserForm_Initialize
If ListBox1.ListCount > 0 Then ListBox1.ListIndex = 0
End If
End Sub
04 Speichern eines Datensatzes
Private Sub CommandButton3_Click()
Dim i As Long
If ListBox1.ListIndex > -1 Then
If Trim(CStr(TextBox1.Text)) <> "" Then
With Worksheets("Eingabe")
.Cells(ListBox1.ListIndex + 3, "A") = CDate(TextBox1)
.Cells(ListBox1.ListIndex + 3, "C") = TextBox3
.Cells(ListBox1.ListIndex + 3, "B") = ListBox1.ListIndex + 3
For i = 207 To 251
.Cells(ListBox1.ListIndex + 3, i) = _
CLng(Me.Controls("TextBox" & CStr(i)))
Next i
'#### verm. hier runden ####
For i = 252 To 266
.Cells(ListBox1.ListIndex + 3, i) = _
Round(Me.Controls("TextBox" & CStr(i)), 2)
Next i
For i = 267 To 269
.Cells(ListBox1.ListIndex + 3, i) = _
CLng(Me.Controls("TextBox" & CStr(i)))
Next i
'#### verm. hier runden ####
For i = 270 To 272
.Cells(ListBox1.ListIndex + 3, i) = _
Round(Me.Controls("TextBox" & CStr(i)))
Next i
End With
Call UserForm_Initialize
If ListBox1.ListCount > 0 Then ListBox1.ListIndex = 0
Else
MsgBox "Sie müssen mindestens einen Namen eingeben!", _
vbCritical + vbOKOnly, "FEHLER!"
End If
End If
End Sub
05 Beenden des Userform1
Private Sub CommandButton4_Click()
Unload Me
End Sub
06 ?
Private Sub ListBox1_Click()
Dim i As Long
07 Kaufmännisches Runden von Spalte: 207 - 272
With Worksheets("Eingabe")
TextBox1 = .Cells(ListBox1.ListIndex + 3, 1)
TextBox2 = .Cells(ListBox1.ListIndex + 3, 2)
TextBox3 = .Cells(ListBox1.ListIndex + 3, 3)
For i = 207 To 272
Me.Controls("TextBox" & CStr(i)) = .Cells(ListBox1.ListIndex + 3, i)
Next i
End With
End Sub
08 ?
Private Sub TextBox1_AfterUpdate()
TextBox3 = Format(CDate(TextBox1), "DDDD")
TextBox2 = ListBox1.ListIndex + 3
End Sub
09 ?
Private Sub UserForm_Activate()
If ListBox1.ListCount > 0 Then ListBox1.ListIndex = 0
End Sub
10 ?
Private Sub UserForm_Initialize()
Dim lZeile As Long, i As Long, raBereich As Range
With Worksheets("Eingabe")
Set raBereich = .Range("A3:A" & .Cells(.Rows.Count, "A").End(xlUp).Row)
End With
ListBox1.List = raBereich.Value
Set raBereich = Nothing
End Sub