24.06.2016, 13:38
Hallo,
das wäre jetzt mein Vorschlag:
Gruß Uwe
das wäre jetzt mein Vorschlag:
Code:
Option Explicit
Private Sub ComboBox1_Click()
Dim i As Long
If ComboBox1.ListIndex <> 0 Then
For i = 1 To 24
Me.Controls("TextBox" & i) = Cells(ComboBox1.ListIndex + 3, i).Value
Next i
Else
For i = 1 To 24
Me.Controls("TextBox" & i) = ""
Next i
End If
End Sub
Private Sub CommandButton1_Click()
Dim i As Long
If ComboBox1.ListIndex > 0 Then
Rows(ComboBox1.ListIndex + 3).Delete
For i = 1 To 24
Me.Controls("TextBox" & i) = ""
Next i
UserForm_Initialize
End If
End Sub
Private Sub CommandButton2_Click()
Dim i As Long
Dim xZeile As Long
If TextBox1 = "" Then Exit Sub
If ComboBox1.ListIndex = 0 Then
xZeile = Cells(Rows.Count, 1).End(xlUp).Row + 1
Else
xZeile = ComboBox1.ListIndex + 3
End If
For i = 1 To 24
Select Case i
Case Is = 2, 18, 20, 22, 23 'Datumfelder
If IsDate(Me.Controls("TextBox" & i)) Then
Cells(xZeile, i).Value = CDate(Me.Controls("TextBox" & i))
Else
Cells(xZeile, i) = ""
End If
Case Else
Cells(xZeile, i).Value = Me.Controls("TextBox" & i)
End Select
Me.Controls("TextBox" & i) = ""
Next i
Range("A3:AT" & xZeile).Sort Key1:=Range("A4"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
UserForm_Initialize
End Sub
Private Sub UserForm_Initialize()
Dim i As Long
ComboBox1.Clear
ComboBox1.AddItem "Neuen Patienten hinzufügen"
For i = 4 To Cells(Rows.Count, 1).End(xlUp).Row
ComboBox1.AddItem Cells(i, 1).Value & ", " & Cells(i, 2).Value
Next i
ComboBox1.ListIndex = 0
End Sub
Private Sub CommandButton3_Click()
Unload Me
End Sub
Gruß Uwe