ich muß mal auch eine Frage stellen
Ich habe eine Datei mit nachfolgendem Code. Wird die Datei geschlossen. Ist sie immer noch im VBA Editor vorhanden. Und ich habe nicht mal ein Ansatz warum.
Im Code gehts es darum die Spalten A bis E in der aktuellen Zeile mit Rot zu markieren und beim wechsel die Farben wieder zurückzustellen.
Private Sub Workbook_Open() Private Sub Workbook_BeforeClose(Cancel As Boolean) Private Sub Workbook_SheetDeactivate(ByVal Sh As Object) Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range) Sub Zurück()
Code eingefügt mit Syntaxhighlighter 1.16
in ein Modul
Option Explicit
Public Wert(5, 5, 5) As String ' 1=Farbe; 2=Zelle; 3= Register
Public I As Integer
in DieseArbeitsmappe
Option Explicit
If ActiveCell.Column < 6 Then
ActiveSheet.Unprotect
For I = 1 To 5
' Werte auslesen
Wert(I, 1, 1) = Cells(ActiveCell.Row, I).Interior.ColorIndex
Wert(I, 2, 2) = Cells(ActiveCell.Row, I).Address
Wert(I, 3, 3) = ActiveSheet.Name
' Zelle Rot Färben
Cells(ActiveCell.Row, I).Interior.ColorIndex = 3
Next I
ActiveSheet.Protect
End If
End Sub
Zurück
End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Zurück
' neue Werte Auslesen
If ActiveCell.Column < 6 Then
ActiveSheet.Unprotect
For I = 1 To 5
' Werte auslesen
Wert(I, 1, 1) = Cells(ActiveCell.Row, I).Interior.ColorIndex
Wert(I, 2, 2) = Cells(ActiveCell.Row, I).Address
Wert(I, 3, 3) = ActiveSheet.Name
' Zelle ot Färben
Cells(ActiveCell.Row, I).Interior.ColorIndex = 3
Next I
ActiveSheet.Protect
End If
End Sub
Zurück
End Sub
' alte Werte zurücksetzen
Zurück
' neue Werte Auslesen
If ActiveCell.Column < 6 Then
ActiveSheet.Unprotect
For I = 1 To 5
' Werte auslesen
Wert(I, 1, 1) = Cells(ActiveCell.Row, I).Interior.ColorIndex
Wert(I, 2, 2) = Cells(ActiveCell.Row, I).Address
Wert(I, 3, 3) = ActiveSheet.Name
' Zelle ot Färben
Cells(ActiveCell.Row, I).Interior.ColorIndex = 3
Next I
ActiveSheet.Protect
End If
End Sub
If Wert(1, 1, 1) <> "" Then
Worksheets(Wert(1, 3, 3)).Unprotect
For I = 1 To 5
Worksheets(Wert(I, 3, 3)).Range(Wert(I, 2, 2)).Interior.ColorIndex = CInt(Wert(I, 1, 1))
Next I
Worksheets(Wert(1, 3, 3)).Protect
End If
End Sub
Gruß Hajo