Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1520to1524
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Bedingte Formatierung über ganze Zeile

Bedingte Formatierung über ganze Zeile
04.11.2016 12:05:20
Sandro
Hallo zusammen,
ich hatte schon einmal dieses Problem gepostet, aber womöglich hatte ich mich nicht gut verständlich gemacht.
Zunächst mein Code:
Option Explicit
Sub Stuecklistenfilter_PM()
Dim Zeile As Long, i As Long
Dim ZeileEnd As Long, lastRow As Long
Dim strString As String, rngCell As Range
Dim cV As Long, cSt As Long, Kogr As Long
Dim aV, aSt ' ohne Angabe = as Variant; Verwendung als "Array"
Dim fR
Const suchStr = "Kogr", suchV = "V", suchSt = "ST"
Application.ScreenUpdating = False
'Kopfzeilen Fett
Set rngCell = Columns(1).Find(suchStr, LookAt:=xlWhole, LookIn:=xlValues, MatchCase:=False)
If Not rngCell Is Nothing Then
Kogr = rngCell.Row
Rows("1:" & Kogr).EntireRow.Font.Bold = True
Rows("1:" & Kogr).EntireRow.Interior.Color = RGB(255, 255, 255)
Else
MsgBox "Kogr bei der Auswertung mit ausgeben lassen und neu versuchen"
Exit Sub
End If
' Zeilen werden als Vertriebsteil gekennzeichnet (Grün) oder als nicht Vertriebsteil (rot) und  _
_
Kommentarfeld wird eingefügt
Set rngCell = Rows(Kogr).Find(suchV, LookIn:=xlValues, LookAt:=xlWhole)
If Not rngCell Is Nothing Then
cV = rngCell.Column
Else
MsgBox "Spalte " & suchV & " nicht gefunden"
Exit Sub
End If
Set rngCell = Rows(Kogr).Find(suchSt, LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False)
If Not rngCell Is Nothing Then
cSt = rngCell.Column
Else
MsgBox "Spalte " & suchSt & " nicht gefunden"
Exit Sub
End If
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
aV = Cells(1, cV).Resize(lastRow)
aSt = Cells(1, cSt).Resize(lastRow)
For i = Kogr + 1 To lastRow
If aV(i, 1) = "*" Then
Rows(i).Interior.Color = RGB(198, 224, 180)
Else
If aSt(i, 1) = 3 Then
Rows(i).Interior.Color = RGB(221, 235, 247)
Else
Rows(i).Interior.Color = RGB(250, 127, 106)
End If
End If
Next
Columns(cV + 1).Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Cells(Kogr, cV + 1) = "Kommentar "
Der Bereich in dem die Formatierung gelten soll:
In der Spalte in der "Kommentar" steht: Von der Zeile unterhalb von "Kommentar" bis zur letzten benutzten Zeile (variabel).
Die Bedingung ist:
Sobald etwas in diese Zellen eingetragen wird (Wert 0)soll die gesamte Zeile gelb gefärbt werden
Wir Ihr Euch denken könnt, habe ich mir bei dem bestehenden Code bereits helfen lassen, um überhaupt soweit zu kommen ;)
Hier der Link zur Datei:
https://www.herber.de/bbs/user/109194.xlsm
Vielleicht kann jemand helfen?
Danke und schöne Grüße,
Sandro

3
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Bedingte Formatierung über ganze Zeile
04.11.2016 15:19:38
Michael
Hi,
dann etwa so:
Sub Stuecklistenfilter_PM()
Dim Zeile As Long, i As Long
Dim ZeileEnd As Long, lastRow As Long
Dim strAdr As String, rngCell As Range
Dim cV As Long, cSt As Long, Kogr As Long
Dim aV, aSt ' ohne Angabe = as Variant; Verwendung als "Array"
Const suchStr = "Kogr", suchV = "V", suchSt = "St"
'Kopfzeilen Fett
Set rngCell = Columns(1).Find(suchStr, LookAt:=xlWhole, LookIn:=xlValues, MatchCase:=False)
If Not rngCell Is Nothing Then
Kogr = rngCell.Row
Rows("1:" & Kogr).EntireRow.Font.Bold = True
Else
MsgBox "Kogr bei der Auswertung mit ausgeben lassen und neu versuchen"
Exit Sub
End If
' Zeilen werden als Vertriebsteil gekennzeichnet (Grün) oder als nicht Vertriebsteil (gelb) und  _
Kommentarfeld wird eingefügt
Set rngCell = Rows(Kogr).Find(suchV, LookIn:=xlValues, LookAt:=xlWhole)
If Not rngCell Is Nothing Then
cV = rngCell.Column
Else
MsgBox "Spalte " & suchV & " nicht gefunden"
Exit Sub
End If
Set rngCell = Rows(Kogr).Find(suchSt, LookIn:=xlValues, LookAt:=xlWhole)
If Not rngCell Is Nothing Then
cSt = rngCell.Column
Else
MsgBox "Spalte " & suchSt & " nicht gefunden"
Exit Sub
End If
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
Stop
'Application.ScreenUpdating = False
aV = Cells(1, cV).Resize(lastRow)
aSt = Cells(1, cSt).Resize(lastRow)
For i = Kogr + 1 To lastRow
If aV(i, 1) = "*" Then
Rows(i).Interior.ColorIndex = 43
Else
If aSt(i, 1) = 3 Then
Rows(i).Interior.ColorIndex = 7
Else
Rows(i).Interior.ColorIndex = 3
End If
End If
Next
Columns(cV + 1).Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Cells(Kogr, cV + 1) = "Kommentar "
strAdr = "$" & Cells(Kogr + 1, cV + 1).Address(0, 0)
With Range("A" & Kogr + 1 & ":S" & lastRow) ' hier mal nur bis Spalte S
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=" & strAdr & "0"
'        "=ODER(" & strAdr & "0;" & strAdr & "="""")"
.FormatConditions(.FormatConditions.Count).SetFirstPriority
.FormatConditions(1).Interior.Color = vbYellow
.FormatConditions(1).StopIfTrue = False
End With

Mit der Bedingung 0 werden leere Zellen nicht erkannt (die ganze Spalte ist ja zunächst leer), d.h. Du kannst mal testhalber die untere Bedingung mit dem ODER verwenden.
Schöne Grüße,
Michael
Anzeige
AW: Bedingte Formatierung über ganze Zeile
04.11.2016 15:49:33
Sandro
Hi Michael,
das funktioniert (wie von Dir schon gewohnt) perfekt! Die Bedingung aus Deinem Code ist genau das was es tun soll, eine "0" wird hier nicht eingetragen.
Du glaubst ja gar nicht wie lange ich da jetzt gesessen bin; ohne Erfolg. Für die Zukunft weiß ich jetzt wie ich so ein Problem angehen muss!
Dafür, und für die schnelle Hilfe, vielen Dank!
Schöne Grüße,
Sandro
very nice,
04.11.2016 16:19:59
Michael
Sandro (oder Pseudo),
mich freut's auch, daß es geht - derweil ich die bedingten Formatierungen sparsam bis gar nicht einsetze: der Code ist mehr oder weniger aus dem Makrorekorder übernommen und angepaßt.
Ich hatte die(se) Frage schon gesehen gehabt, aber gestern lief's nicht recht...
Happy Exceling,
Michael
Anzeige

324 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige