AW: Max if mit zwei Bedingungen
31.07.2013 23:49:05
Sebastian
Hallo,
Ich habe mit Hilfe dieses Threads ( http://www.ozgrid.com/forum/showthread.php?t=181300&p=677385#post677385
) und ein bisschen Anpassen meine Funktion hinbekommen.
Public Function MaxIf2(rngEvaluate1 As Range, _
strCondition1 As String, _
rngEvaluate2 As Range, _
strCondition2 As String, Optional rngValues As Range = Nothing) As Variant
'Bestimmt das Maximum mit zwei Bedingungen. Angepasst am 31.7.2013 mit Excel 2010
'These functions have been developed by Alan Forster on 27th September 2004.
'After years of desire he has actually written them!
'The functions use the same evaluation methods as the CountIf and SumIf functions
Dim varValue As Variant
Dim bolValueSet As Boolean
Dim intRow As Integer, _
intCol As Integer
If (rngValues Is Nothing) Then Set rngValues = rngEvaluate2
bolValueSet = False
If Not RangesOK2(rngEvaluate1, rngEvaluate2, rngValues) Then
'Return an error value
varValue = "Error in range selection"
Else
'If the ranges are not identically sized can not get this far!
For intRow = 1 To rngEvaluate1.Rows.Count
For intCol = 1 To rngEvaluate1.Columns.Count
If Application.CountIf(rngEvaluate1(intRow, intCol), strCondition1) = 1 And _
Application.CountIf(rngEvaluate2(intRow, intCol), strCondition2) = 1 Then
If bolValueSet Then
If varValue
Wer will, darf gerne nochmal drüber schauen und Hinweise geben, ob ich irgendwo einen Fehler gemacht habe. Nach ersten Tests bin ich aber ganz optimistisch, dass mir das wirklich gelungen ist.
Viele Grüße