Hallo nighty,
vielen Dank für die Mühe, die du dir gemacht hast!!! Der Code ist in vieler Hinsicht sehr interessant, passt aber noch nicht ganz zu meinem Problem. Ich habe eine Lösung gefunden, die funktioniert, aber sicher nicht sehr "elegant" ist.....:
Spalten A=Name, B= Frequenz (1-4 oder ohne für die Anzahl im Monat, auch als Kombination z.B. "2 4" möglich), C= Wochentag 1-7, D und E Tages-Anfangs- und Endzeit.
Sub TerminplanR()
Dim Tag As String, x As String
k = 13
m = 0
For m = 0 To 6
Cells(k, 2) = Cells(13, 2) + m
For i = 2 To 10
Tag = Cells(13, 2) + m
x = Weekday(Tag)
If InStr(Cells(i, 3), x) > 0 And InStr(Cells(i, 2), "1") > 0 Or (InStr(Cells(i, 3), x) > 0 And Cells(i, 2) = "") Then
Cells(k, 1) = Cells(i, 1)
Cells(k, 3) = Cells(i, 4)
Cells(k, 4) = Cells(i, 5)
Cells(k, 5) = x
k = k + 1
End If
Next
Next
For m = 7 To 13
Cells(k, 2) = Cells(13, 2) + m
For i = 2 To 10
Tag = Cells(13, 2) + m
x = Weekday(Tag)
If InStr(Cells(i, 3), x) > 0 And InStr(Cells(i, 2), "2") > 0 Or (InStr(Cells(i, 3), x) > 0 And Cells(i, 2) = "") Then
Cells(k, 1) = Cells(i, 1)
Cells(k, 3) = Cells(i, 4)
Cells(k, 4) = Cells(i, 5)
Cells(k, 5) = x
k = k + 1
End If
Next
Next
For m = 14 To 20
Cells(k, 2) = Cells(13, 2) + m
For i = 2 To 10
Tag = Cells(13, 2) + m
x = Weekday(Tag)
If InStr(Cells(i, 3), x) > 0 And InStr(Cells(i, 2), "3") > 0 Or (InStr(Cells(i, 3), x) > 0 And Cells(i, 2) = "") Then
Cells(k, 1) = Cells(i, 1)
Cells(k, 3) = Cells(i, 4)
Cells(k, 4) = Cells(i, 5)
Cells(k, 5) = x
k = k + 1
End If
Next
Next
For m = 21 To 30
Cells(k, 2) = Cells(13, 2) + m
For i = 2 To 10
Tag = Cells(13, 2) + m
x = Weekday(Tag)
If InStr(Cells(i, 3), x) > 0 And InStr(Cells(i, 2), "4") > 0 Or (InStr(Cells(i, 3), x) > 0 And Cells(i, 2) = "") Then
Cells(k, 1) = Cells(i, 1)
Cells(k, 3) = Cells(i, 4)
Cells(k, 4) = Cells(i, 5)
Cells(k, 5) = x
k = k + 1
End If
Next
Next
End Sub
Im Ergebnis wird eine Liste der entsprechenden Termine nach Tagen/Namen und Zeiten erstellt. Vlt. gibt es hier noch Verbesserungsmöglichkeiten...??
Gruß Andreas