Hallo Andreas,
der Code gehört ins CodeModul des Arbeitsblattes "Archiv". Rechtsklick auf den Tabellenblattreiter, Code anzeigen, Code rechts ins Codefenster kopieren.
Der Code startet automatisch, sobald du im Blatt "Archiv" in Spalte H, ab Zeile 2 ein Datum einträgst. Das geht aber nur, wenn das Datum händisch eingetragen wird.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Long
Dim loLetzte As Long
loLetzte = Sheets("Hauptseite").Cells(Rows.Count, 3).End(xlUp).Row
If Target.Column = 8 Then
If Target.Count > 1 Then
Application.EnableEvents = False
MsgBox "Mehrfachauswahl nicht zulässig"
Application.Undo
Application.EnableEvents = True
Exit Sub
End If
If Target.Row > 1 Then
If Target <> "" And IsDate(Target) Then
If Target.Row = 2 Then
Target.Offset(0, 11) = Sheets("Hauptseite").Cells(6, 3)
ElseIf Target.Row > 2 Then
Target.Offset(0, 11) = Target.Offset(-1, 11) + 1
End If
For i = 6 To loLetzte
If Target.Row > 2 And Target.Offset(-1, 11) = Sheets("Hauptseite").Cells(i, 4) Then
Target.Offset(0, 11) = Sheets("Hauptseite").Cells(i + 1, 3)
Exit For
End If
Next i
End If
End If
End If
End Sub
Gruß und schönes Neues Jahr
Werner
|