Aktiven Autofilter farblich markieren
Beate
Hallo Erik,
diesen Code hatte ich mal von Boris:
Er gehört komplett in das entsprechende Klassenmodul der Tabelle.
Gefiltert wird in Zeile 1 - das musst du natürlich bei Bedarf anpassen.
Option Explicit
Private Sub Worksheet_Activate()
[iv65536].FormulaLocal = "=ZUFALLSZAHL()"
End Sub
Private Sub Worksheet_Calculate()
Dim F As Integer, aSh As Worksheet
Set aSh = ActiveSheet
Application.EnableEvents = True
Rows(1).Interior.ColorIndex = xlNone
If aSh.AutoFilterMode = False Then
Application.EnableEvents = False
Else
For F = 1 To aSh.AutoFilter.Filters.Count
If aSh.AutoFilter.Filters(F).On Then
aSh.Cells(1, F).Interior.ColorIndex = 4 'grün
End If
Next
End If
Application.EnableEvents = True
End Sub
Private Sub Worksheet_Deactivate()
[iv65536] = ""
End Sub
Die vorübergehend durch Worksheet_Activate und Worksheet_Deactivate eingefügte Zufallszahl in Zelle IV65536 bewirkt, dass diese nach dem Filtern neuberechnet wird und dies stößt das Worksheet_Calculate Makro an, welches die Autofilterzelle einfärbt.
Gruß,
Beate