Clever-Excel-Forum

Normale Version: Bedingte Formatierung
Du siehst gerade eine vereinfachte Darstellung unserer Inhalte. Normale Ansicht mit richtiger Formatierung.
Hallo,

ich habe mir einen Code zusammen gestellt mit dem ich in Bereichen je nach Eingabe eine Farbliche Kennzeichnung machen lasse.
Leider funktioniert der Code nur wenn ich die Eingabe direkt in die Felder mache, und nicht wenn die Daten aus einer anderen Zelle geholt (z.B. =andereTabelle!C9) werden.
Wenn ich auf Worksheet_SelectionChange umstelle und die Zellen mit dem Inhalt dann anklicke, wird die Formatierung ausgeführt.


Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
       ' Füllfarbe
   ' für Schrift RaZelle.Font.ColorIndex
   Dim RaBereich As Range                          ' Variable für Bereich
   Dim RaZelle As Range                            ' Variable für Zelle
   'Set RaBereich = Range("C9:GF9, C11:GF11")       ' Bereich der Wirksamkeit
   ' noch mehr Bereiche
   Set RaBereich = Union(Range("C13:GF13 , C9:GF9, C11:GF11, C15:GF15, C17:GF17 , C19:GF19"), _
      Range("C21:GF21, C23:GF23, C25:GF25, C27:GF27 , C29:GF29 , C31:GF31"), _
       Range("C33:GF33 , C35:GF35 , C37:GF37 , C39:GF39 , C41:GF41 , C43:GF43"), _
      Range("C45:GF45 , C47:GF47, C49:GF49 , C51:GF51 , C53:GF53"), _
       Range("C55:GF55 , C57:GF57 , C59:GF59 , C61:GF61 , C63:GF63"), _
      Range("C65:GF65, C67:GF67 , C69:GF69 , c71:gf71 , C73:GF73 , C75:GF75"), _
      Range("C77:GF77 , C79:GF79, C81:GF81 , C83:GF83 , C85:GF85"), _
      Range("C87:GF87 , C89:GF89, C91:GF91"))
   
   Set RaBereich = Intersect(RaBereich, Target)
   If Not RaBereich Is Nothing Then
       'ActiveSheet.Unprotect ("PW")
       For Each RaZelle In RaBereich
           'With RaZelle
               Select Case UCase(.Value)           ' Umwandlung der Eingabe in Großbuchstaben
                   
                   
                   Case "PKG20"
                       .Interior.ColorIndex = 26        ' Füllfarbe Pink
                       .Font.Color = 1                 ' Schriffarbbe schwarz
                       .NumberFormat = "General"   ' Zellenformat Standard
                   Case "PKG40"
                       .Interior.ColorIndex = 26     ' Füllfarbe Pink
                       .Font.Color = 1                 ' Schriffarbe schwaz
                       .NumberFormat = "General"
                   Case "PVM20"
                       .Interior.ColorIndex = 26         ' Füllfarbe Pink
                       .Font.Color = 1                     ' Schriffarbbe schwarz
                       .NumberFormat = "General"   ' Zellenformat Standard
                   Case "PVM40"
                       .Interior.ColorIndex = 26     ' Füllfarbe Pink
                       .Font.Color = 1                 ' Schriffarbe automatisch
                       .NumberFormat = "General"
                   Case "PM20"
                       .Interior.ColorIndex = 26         ' Füllfarbe Pink
                       .Font.Color = 1                 ' Schriffarbbe schwarz
                       .NumberFormat = "General"   ' Zellenformat Standard
                   Case "PM40"
                       .Interior.ColorIndex = 26     ' Füllfarbe Pink
                       .Font.Color = 1                 ' Schriffarbe automatisch
                       .NumberFormat = "General"
                   Case "MASSAGE"
                       .Interior.ColorIndex = 23       ' Füllfarbe Blau
                       .Font.Color = 1
                       .NumberFormat = "General"       ' Zellformat nicht sichtbar
                   Case "FUSSPFLEGE"
                       .Interior.ColorIndex = 10     ' Füllfarbe Grün
                       .Font.Color = 1
                       .NumberFormat = "General"
                   Case "PODOLOGIE"
                       .Interior.ColorIndex = 10     ' Füllfarbe Grün
                       .Font.Color = 1
                       .NumberFormat = "General"
                   Case "EM"
                       .Interior.ColorIndex = 28       ' Füllfarbe Hellblau
                       .Font.Color = 1                 ' Schriftfarbe schwarz
                       .NumberFormat = "General"
                   Case "CMD"
                       .Interior.ColorIndex = 14       ' Füllfarbe Türkis
                       .Font.Color = 1                 ' Schriftfarbe schwarz
                       .NumberFormat = "General"
                   Case "HM"
                       .Interior.ColorIndex = 28              ' Füllfarbe Hellblau
                       .Font.Color = 1                  ' Schriftfarbe schwarz
                       .NumberFormat = "General"
                   Case "EKG"
                       .Interior.ColorIndex = 19           ' Füllfarbe creme
                       .Font.Color = 1                 ' Schriftfarbe schwarz
                       .NumberFormat = "General"
                   Case "CMDP20"
                       .Interior.ColorIndex = 26         ' Füllfarbe Pink
                       .Font.Color = 1                     ' Schriffarbbe schwarz
                       .NumberFormat = "General"       ' Zellenformat Standard
                   Case "CMDP40"
                       .Interior.ColorIndex = 26            ' Füllfarbe rosa
                       .Font.Color = 1                     ' Schriftfarbe schwarz
                       .NumberFormat = "General"
                   Case "KG"
                       .Interior.ColorIndex = 35             ' Füllfarbe Hellgrün
                       .Font.Color = 1
                       .NumberFormat = "General"
                   Case "ULTRA"
                       .Interior.ColorIndex = 19              ' Füllfarbe creme
                       .Font.Color = 1
                       .NumberFormat = "General"
                   Case "LYM60"
                       .Interior.ColorIndex = 6              ' Füllfarbe gelb
                       .Font.Color = 1
                       .NumberFormat = "General"
                   Case "LYM45"
                       .Interior.ColorIndex = 6              ' Füllfarbe gelb
                       .Font.Color = 1
                       .NumberFormat = "General"
                   Case "LYM30"
                       .Interior.ColorIndex = 6                ' Füllfarbe gelb
                       .Font.Color = 1
                       .NumberFormat = "General"
                   Case "VM"
                       .Interior.ColorIndex = 28               ' Füllfarbe
                       .Font.Color = 1
                       .NumberFormat = "General"
                   Case "BAD"
                       .Interior.ColorIndex = 19               ' Füllfarbe
                       .Font.Color = 1
                       .NumberFormat = "General"
                   Case "BM"
                       .Interior.ColorIndex = 28               ' Füllfarbe hellblau
                       .Font.Color = 1                         ' Schriftfarbe schwarz
                       .NumberFormat = "General"
                   Case "HAUSBESUCH"
                       .Interior.ColorIndex = 19               ' Füllfarbe creme
                       .Font.Color = 1                         ' Schriftfarbe schwarz
                       .NumberFormat = "General"
                   Case "Leer"
                       .Interior.ColorIndex = 19             ' Füllfarbe weis
                       .Font.Color = 1                         ' Schriftfarbe schwarz
                       .NumberFormat = "General"
                   Case "Leer"
                       .Interior.ColorIndex = 22            ' Füllfarbe weis
                       .Font.Color = 1                         ' Schriftfarbe schwarz
                       .NumberFormat = "General"
                   Case "Leer"
                       .Interior.ColorIndex = 19             ' Füllfarbe beige
                       .Font.Color = 1                         ' Schriftfarbe schwarz
                       .NumberFormat = "General"
                   Case "Leer"
                       .Interior.ColorIndex = 22            ' Füllfarbe pink
                       .Font.Color = 1                         ' Schriftfarbe schwarz
                       .NumberFormat = "General"
                   Case "Leer"
                       .Interior.ColorIndex = 19             ' Füllfarbe beige
                       .Font.Color = 1                         ' Schriftfarbe schwarz
                       .NumberFormat = "General"
                   Case "Leer"
                       .Interior.ColorIndex = 45            ' Füllfarbe orange
                       .Font.Color = 1                         ' Schriftfarbe schwarz
                       .NumberFormat = "General"
                   Case "Leer"
                       .Interior.ColorIndex = 3           ' Füllfarbe rot
                       .Font.Color = 1                     ' Schriftfarbe schwarz
                       .NumberFormat = "General"
                   Case "Leer"
                       .Interior.ColorIndex = 32          ' Füllfarbe
                       .Font.Color = 0                        ' Schriftfarbe schwarz
                       .NumberFormat = "General"
                   Case Else
                       ' keine Füllfarbe, ColorIndex nicht Color
                       .Interior.ColorIndex = 15       'Füllfarbe grau
                       .Font.ColorIndex = 1                'Schriftfarbe schwarz
                       .NumberFormat = "General"
               End Select
           'End With
       Next RaZelle
       'ActiveSheet.Protect ("PW")
   End If
   Set RaBereich = Nothing                         ' Variable leeren
End Sub
Hallöchen,

eine Formel löst kein Change-Ereignis aus. Dafür gibt es das Calculate-Ereignis. Allerdings hat das nun wieder keinen Target ... Eventuell müsstest Du auf dem anderen Blatt ein Change-Ereignis für die Zelle C9 auswerten bzw. programmieren.