• Privacywetgeving
    Het is bij Helpmij.nl niet toegestaan om persoonsgegevens in een voorbeeld te plaatsen. Alle voorbeelden die persoonsgegevens bevatten zullen zonder opgaaf van reden verwijderd worden. In de vraag zal specifiek vermeld moeten worden dat het om fictieve namen gaat.

Als voorwaardelijke opmaak = 3 dan .....

Status
Niet open voor verdere reacties.

Demeter

Verenigingslid
Lid geworden
24 mei 2006
Berichten
1.659
Daar is ie weer :),

Ik wil graag met een loop, whoehaaaa, kijken hoeveel van mijn cellen in een bereik voorwaardelijk rood zijn gemaakt.

Code:
Sub tellen ()
dim c as Range
dim d as Integer

d = 0

For each c in Range("J3:J200")
      [COLOR="Red"]if c.formatconditions(1).interior.Colorindex = 3 then[/COLOR]
            c = 1
            d = d + c
       end if

if d > 0 then
     msgbox "Let op!!! Er moeten " & d & " artikelen gekeurd worden."
end if

end sub

Maar ik krijg mijn c.formatconditions niet juist ingevoerd?
Iemand een voorzet van links? of van rechts? misschien een diepe pass?


Thanks,
Ferenc
 
Hoi Demeter,
Is het niet eenvoudiger te tellen welke cellen aan de voorwaarde voldoen om ze rood te kleuren?
Dan kijk je naar de celinhoud i.p.v. de opmaak.

Richard
 
Is het niet eenvoudiger te tellen welke cellen aan de voorwaarde voldoen om ze rood te kleuren?

Dat zou ik ook denken.

Alleen kan het voorkomen dat de voorwaardelijke opmaak zeer uitgebreid is en dat het voordeel niet meer opweegt tegen de nadelen.

Trouwens, wat je vraagt is extreem moeilijk Ferenc...

Wigi
 
Hier vind je alles wat je nodig hebt... maar watch out... quite difficult... :confused:

EDIT: link vergeten, bedankt Richard. Blijkt wel dezelfde link te zijn als Richard in de volgende post aangeeft.
 
Laatst bewerkt:
Hier het antwoord van vitalnes op een soortgelijke vraag:

"Ronald has a worksheet that utilizes conditional formatting. The conditions result in the cells being different colors. He wants to count the number of cells that are red in the worksheet. He knows how to create a macro that will examine the cell color and do a count if a cell is formatted directly as red, but the macro won't work with cells that are conditionally formatted. Ronald wants to know if there is a way to count these conditionally red cells, as well.
You cannot directly check in a macro what the color of a cell is based on a conditional format. There are ways you can work around this with a macro, but it is not for the faint-of-heart. The following page on Chip Pearson's site demonstrates the difficulty in determining conditional colors:
http://www.cpearson.com/excel/CFColors.htm
Given the difficulty of the task, it may just be easier to recreate the conditions within the macro, and then see which cells meet these conditions. The result is that you count cells matching conditions rather than count cells that are colored red as a result of those conditions. This should yield the same count of cells, but is much easier to handle programmatically.
Of course, the only caveat to this solution is that you will need to keep the conditions in the macro and the conditions in the conditional formats in sync with each other. If you change one and fail to change the other, then you won't get the desired results.
"

Groeten en veel succes!

Richard
 
Hiermee is waarschijnlijk een paar uur werk bespaard voor jou...

Code:
Sub tellen()
    Dim rngToDo As Range
    Set rngToDo = Range("J3:J200")
    
    MsgBox "Let op! Er moeten " & IIf(SumByCFColorIndex(rngToDo, 3) = 0, "geen", SumByCFColorIndex(rngToDo, 3)) _
        & " artikelen gekeurd worden."
End Sub

Function SumByCFColorIndex(Rng As Range, CI As Integer)
    Dim R As Range, Total As Double
    For Each R In Rng.Cells
        If ColorIndexOfCF(R, False) = CI Then
            Total = Total + 1
        End If
    Next R
    SumByCFColorIndex = Total
End Function

Function ColorIndexOfCF(Rng As Range, Optional OfText As Boolean = False) As Integer

Dim AC As Integer
AC = ActiveCondition(Rng)
If AC = 0 Then
    If OfText = True Then
       ColorIndexOfCF = Rng.Font.ColorIndex
    Else
       ColorIndexOfCF = Rng.Interior.ColorIndex
    End If
Else
    If OfText = True Then
       ColorIndexOfCF = Rng.FormatConditions(AC).Font.ColorIndex
    Else
       ColorIndexOfCF = Rng.FormatConditions(AC).Interior.ColorIndex
    End If
End If

End Function

Function ActiveCondition(Rng As Range) As Integer
Dim Ndx As Long
Dim FC As FormatCondition
Dim Temp As Variant
Dim Temp2 As Variant

If Rng.FormatConditions.Count = 0 Then
    ActiveCondition = 0
Else
    For Ndx = 1 To Rng.FormatConditions.Count
        Set FC = Rng.FormatConditions(Ndx)
        Select Case FC.Type
            Case xlCellValue
            Select Case FC.Operator
                Case xlBetween
                    Temp = GetStrippedValue(FC.Formula1)
                    Temp2 = GetStrippedValue(FC.Formula2)
                    If IsNumeric(Temp) Then
                       If CDbl(Rng.Value) >= CDbl(FC.Formula1) And _
                           CDbl(Rng.Value) <= CDbl(FC.Formula2) Then
                           ActiveCondition = Ndx
                           Exit Function
                       End If
                   Else
                      If Rng.Value >= Temp And _
                         Rng.Value <= Temp2 Then
                         ActiveCondition = Ndx
                         Exit Function
                      End If
                   End If

                Case xlGreater
                    Temp = GetStrippedValue(FC.Formula1)
                    If IsNumeric(Temp) Then
                       If CDbl(Rng.Value) > CDbl(FC.Formula1) Then
                          ActiveCondition = Ndx
                          Exit Function
                       End If
                    Else
                       If Rng.Value > Temp Then
                          ActiveCondition = Ndx
                          Exit Function
                       End If
                    End If

                Case xlEqual
                    Temp = GetStrippedValue(FC.Formula1)
                    If IsNumeric(Temp) Then
                       If CDbl(Rng.Value) = CDbl(FC.Formula1) Then
                           ActiveCondition = Ndx
                           Exit Function
                       End If
                    Else
                       If Temp = Rng.Value Then
                          ActiveCondition = Ndx
                          Exit Function
                       End If
                    End If


                Case xlGreaterEqual
                    Temp = GetStrippedValue(FC.Formula1)
                    If IsNumeric(Temp) Then
                       If CDbl(Rng.Value) >= CDbl(FC.Formula1) Then
                           ActiveCondition = Ndx
                           Exit Function
                       End If
                    Else
                       If Rng.Value >= Temp Then
                          ActiveCondition = Ndx
                          Exit Function
                       End If
                    End If

              
                Case xlLess
                    Temp = GetStrippedValue(FC.Formula1)
                    If IsNumeric(Temp) Then
                        If CDbl(Rng.Value) < CDbl(FC.Formula1) Then
                           ActiveCondition = Ndx
                           Exit Function
                        End If
                    Else
                        If Rng.Value < Temp Then
                           ActiveCondition = Ndx
                           Exit Function
                        End If
                    End If

                Case xlLessEqual
                    Temp = GetStrippedValue(FC.Formula1)
                    If IsNumeric(Temp) Then
                       If CDbl(Rng.Value) <= CDbl(FC.Formula1) Then
                          ActiveCondition = Ndx
                          Exit Function
                       End If
                    Else
                       If Rng.Value <= Temp Then
                          ActiveCondition = Ndx
                          Exit Function
                       End If
                    End If


                Case xlNotEqual
                    Temp = GetStrippedValue(FC.Formula1)
                    If IsNumeric(Temp) Then
                       If CDbl(Rng.Value) <> CDbl(FC.Formula1) Then
                          ActiveCondition = Ndx
                          Exit Function
                       End If
                    Else
                       If Temp <> Rng.Value Then
                          ActiveCondition = Ndx
                          Exit Function
                       End If
                    End If

               Case xlNotBetween
                    Temp = GetStrippedValue(FC.Formula1)
                    Temp2 = GetStrippedValue(FC.Formula2)
                    If IsNumeric(Temp) Then
                       If Not (CDbl(Rng.Value) <= CDbl(FC.Formula1)) And _
                          (CDbl(Rng.Value) >= CDbl(FC.Formula2)) Then
                          ActiveCondition = Ndx
                          Exit Function
                       End If
                    Else
                       If Not Rng.Value <= Temp And _
                          Rng.Value >= Temp2 Then
                          ActiveCondition = Ndx
                          Exit Function
                       End If
                    End If
               Case Else
                    Debug.Print "UNKNOWN OPERATOR"
           End Select


        Case xlExpression
            If Application.Evaluate(FC.Formula1) Then
               ActiveCondition = Ndx
               Exit Function
            End If

        Case Else
            Debug.Print "UNKNOWN TYPE"
       End Select
    Next Ndx
End If
ActiveCondition = 0

End Function

Function GetStrippedValue(CF As String) As String
    Dim Temp As String
    If InStr(1, CF, "=", vbTextCompare) Then
       Temp = Mid(CF, 3, Len(CF) - 3)
       If Left(Temp, 1) = "=" Then
           Temp = Mid(Temp, 2)
       End If
    Else
       Temp = CF
    End If
    GetStrippedValue = Temp
End Function

Voer de macro "tellen" uit.

Alle krediet aan Charles "Chip" Pearson.

Wigi
 
Damn :evil: ,

Dacht toch echt dat ik op de juiste weg was!!!!!
Raar dat het zo omslag is. Is dit in 2007 ook zo geregeld?

In ieder geval bedankt voor de info en het zoekwerk.

Ik ga er eens lekker voor zitten om alles door te nemen.
Whoeha.............

Dank jullie wel mannen :thumb:

Groet,
Ferenc
 
Nogmaals bedankt voor de code en de tijd die e rin is gaan zitten.
Ben gisterenavond bezig geweest om alles op een rijtje te zetten en ben er achter gekomen dat het toch, voor mij, te ingewikkeld is om zo verder te gaan.

Ga toch verder met jullie eerste advies, om de cellen te bekijken of ze aan een voorwaarde voldoen en deze dan rood maken en tellen mbv VBA. Het gehele voorwaardelijke opmaak idee is (tijdelijk) van de baan.

Ben voor de nieuwe methode ook al weer tegen een probleem aangelopen (mijn VBA kennis laat duidelijk nog te wensen over).
Deze is hier gepost:
http://www.helpmij.nl/forum/newthread.php?do=newthread&f=5



Bedankt en groeten,
Ferenc

ps.
dit is tevens een bericht voor toekomstige bezoekers zodat, er voor hun ook meer duidelijk is.
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan