mit einem genialen Tipp von Hajo habe ich einzelne Zellenbereiche gesperrt, hier ein Teil des Codes:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
' Exit Sub
' erstellt von Hajo Ziplies 10.01.03
Dim RaBereich As Range, RaZelle As Range ' Bereich der Wirksamkeit
Set RaBereich = Range("C1:AG1")
For Each RaZelle In Range(Target.Address)
If Intersect(RaZelle, RaBereich) Is Nothing Then
Else
Range("A1").Select
Exit For
End If
Next RaZelle
In diesen gesperrten Bereich werden per Makro Daten aus einem anderen Blatt eingetragen; das klappt auch. Weil aber nicht in jede Zelle etwas eingetragen wird, sondern auch einige leer bleiben, müssen diese Zellen vorher geleert werden, und genau das geht nicht. Auch hier ein Teil des Codes:
Sub LeeresBlatt()
Application.ScreenUpdating = False
ActiveSheet.Unprotect
Range( _
"C3:AG4,C8:AG9,C13:AG14,C18:AF19,C23:AG24,C28:AF29,C33:AG34,C38:AG39,C43:AF44,C48:AG49,C53:AF54,C58:AG59" _
).Select
Range("C58").Activate
For t = 3 To 58 Step 5
For m = 3 To 33
Cells(t - 1, m).Interior.ColorIndex = -4142
Cells(t - 1, m).Font.Size = 6
Cells(t - 1, m).Font.FontStyle = "Standard"
Cells(t - 1, m).Font.ColorIndex = -4105
Cells(t, m).Font.ColorIndex = -4105
Cells(t, m).Interior.ColorIndex = -4142
Cells(t, m).Font.FontStyle = "Fett"
Cells(t + 1, m).Interior.ColorIndex = -4142
If Cells(t - 1, m) <> "" Then
If Weekday(Cells(t - 1, m), 2) > 5 Then
Cells(t - 1, m).Interior.ColorIndex = 36
Cells(t - 1, m).Font.ColorIndex = 3
Cells(t - 1, m).Font.Size = 8
Cells(t - 1, m).Font.FontStyle = "Fett"
Cells(t + 1, m).Interior.ColorIndex = 36
End If
End If
Next m
Next t
Selection.ClearContents
Die Rückstellung der Farb-, Schrifteinstellungen usw. funktioniert, das Löschen der Zellen nicht. Wenn ich nun Hajos Code mit Exit Sub außer Funktion setze, geht's natürlich wieder. Ist es aber nicht auch möglich, das zu automatisieren? Bzw. kann man das Exit Sub evtl. auch per Makor ein- und wieder austragen lassen? Oder gibt es eine andere Lösung.
Vielen Dank im Voraus
Gruß
Franz