|
VBA - Art bedingte Formatierung |
|
|
|
|
Geschrieben von: Marcus Rose
|
|
Sonntag, 11. Mai 2008 um 22:57 Uhr |
|
Auf diese Art kann man Zellen mit mehr als 3 Formatierungen versehen, was ja so ohne weiteres nicht mit Excel möglich ist. Excel VBA hilft us hier mit verschiedenen Möglichkeiten der Programmierung. An dieser Stelle gebe ich Euch 2 Beispiele zur Lösung. Beide Lösungswege bewerkstelligen, dass die abgebildete Tabelle mit Buchstaben in verschiedenen Farben dargestellt werden können.
| | | | A | B | C | D | E | F | G | H | | 1 | | Montag | Dienstag | Mittwoch | Donnerstag | Freitag | Samstag | Sonntag | | 2 | Name 1 | X | | | | | | | | 3 | Name 2 | | L | | | | | | | 4 | Name 3 | | | T | | | | | | 5 | Name 4 | | | | R | | | | | 6 | Name 5 | | | | | E | | | | 7 | Name 6 | | | | | | F | | | 8 | Name 7 | | | | | | | F | | 9 | Name 8 | | | | | | | | | 10 | Name 9 | | | | | | | | | | |
Möglichkeit 1: Option Explicit Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range) Dim cell As Range For Each cell In Range("B2:H10") If cell.Value = "X" Then cell.Font.ColorIndex = 15 If cell.Value = "L" Then cell.Font.ColorIndex = 3 If cell.Value = "T" Then cell.Font.ColorIndex = 41 If cell.Value = "R" Then cell.Font.ColorIndex = 10 If cell.Value = "R" Then cell.Font.FontStyle = "Fett" If cell.Value = "E" Then cell.Font.ColorIndex = 15 If cell.Value = "F" Then cell.Font.ColorIndex = 3 If cell.Value = "D" Then cell.Interior.ColorIndex = 3 If cell.Value = "" Then cell.Clear Next End Sub Möglichkeit 2:
Option Explicit Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range) Dim cell As Range For Each cell In Range("B2:H10") Select Case cell Case Is = "X" cell.Font.ColorIndex = 15 Case Is = "L" cell.Font.ColorIndex = 3 Case Is = "T" cell.Font.ColorIndex = 41 Case Is = "R" cell.Font.FontStyle = "Fett" cell.Font.ColorIndex = 10 Case Is = "E" cell.Font.ColorIndex = 26 Case Is = "F" cell.Font.ColorIndex = 47 Case Is = "D" cell.Interior.ColorIndex = 47 Case Is = "" cell.Clear End Select Next End Sub
|