Ich habe folgendes Makro hinter einem Button auf einer Excel-Arbeitsmappe:
Private Sub CommandButton1_Click()
Dim x As Long, y As Long, j As Long
Dim MyDatStrg As String
ActiveSheet.Unprotect "0000"
MyDatStrg = InputBox("Bitte Datum angeben", "Datum", Date)
If StrPtr(MyDatStrg) = 0 Then Exit Sub 'Abbrechen gedrückt
If Not IsDate(MyDatStrg) Then Exit Sub 'Kein Datum
x = Cells(Rows.Count, 10).End(xlUp).Row
y = Cells(Rows.Count, 1).End(xlUp).Row
For j = x + 1 To y
If x y Then Range(Cells(x, 11), Cells(x, 13)).AutoFill Destination:=Range(Cells(y, 11), _
Cells(x, 13))
Next
'Schlaufe wird nun ein zweites Mal pro Datensatz durchlaufen um Zellen farbig zu formatieren
For j = x + 1 To y
With Cells(j, 10)
.Value = CDate(MyDatStrg)
.Interior.ColorIndex = 20
End With
With Cells(j, 11)
.Interior.ColorIndex = 6
End With
With Cells(j, 12)
.Interior.ColorIndex = 6
End With
With Cells(j, 13)
.Interior.ColorIndex = 6
End With
Next
Columns("J:O").Select
Selection.Locked = True
Selection.FormulaHidden = False
ActiveSheet.Protect "0000"
End Sub
mittels diesem Code soll ein Datensatz mit einem Datum ab einer Inputbox versehen werden.Das Ganze soll so laufen, dass am Ende die Zellen J:O vor jeglicher Veränderung gesperrt und geschützt sind.
Dazu hab ich diese Zellen J:O mit einem Zellschutz versehen und anschliessend das ganze Blatt geschützt mit Password 0000
Aber leider funzt der Coder zwar, aber die Funktionen mit dem Aufheben des Blattschutzes und Zellen wieder Sperren funzt nicht. - Es wird mir immer gleich das ganze Blatt wieder gesperrt.
Was mach ich in meinem Code falsch ?
Danke für Eure Tips !