|
Alle Änderungen sind markiert:
Sub SetXForStabchen()
Dim ws As Worksheet
Dim cell As Range
Dim currentRowColor As Long
Dim currentCellColor As Long
Dim belowCellColor As Long
Dim whiteColor As Long
Dim greenColor As Long
Dim lastRow As Long
Dim rowIndex As Long
Dim colIndex As Long
' Setze das Arbeitsblatt, das verwendet wird
Set ws = ThisWorkbook.Worksheets("Tabelle1") ' Passe den Namen des Arbeitsblatts an
' Definiere die Farben
whiteColor = RGB(255, 255, 255) ' Weiß
greenColor = RGB(0, 255, 0) ' Grün
' Finde die letzte Zeile im Arbeitsblatt mit Daten
lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
' Durchlaufe jede Zelle im ausgewählten Bereich
For Each cell In Selection
rowIndex = cell.Row
colIndex = cell.Column
' Bestimme die Farbe der aktuellen Zelle
currentCellColor = cell.Interior.Color
' Bestimme die Farbe der Reihe, in der sich die Zelle befindet
If rowIndex Mod 2 = 1 Then
currentRowColor = greenColor ' Ungerade Reihen sind Grün
Else
currentRowColor = whiteColor ' Gerade Reihen sind Weiß
End If
' Überprüfe die Farbe der darunter liegenden Zelle
If rowIndex < lastRow Then
belowCellColor = ws.Cells(rowIndex + 1, colIndex).Interior.Color
Else
belowCellColor = greenColor ' falls keine darunter liegende Zelle existiert
End If
If belowCellColor = currentRowColor Then
cell.Value = "X"
' Else
' cell.Value = ""
End If
Next cell
End Sub
|