For iavntDaten1 = LBound(avntDaten, 1) To UBound(avntDaten, 1)
For iavntDaten2 = LBound(avntDaten, 2) To UBound(avntDaten, 2)
If avntDaten(iavntDaten1, iavntDaten2) = vntSuchwert Then
avntErgebniswert(iavntSuchwert1, iavntSuchwert2) = iavntDaten1
blnFund = True: Exit For
End If
Next
If blnFund Then Exit For
Next
If blnFund Then
rngSuchwert.Cells(iavntSuchwert1, iavntSuchwert2).Interior.Color = RGB(192, 192, 192)
rngDaten.Cells(iavntDaten1, iavntDaten2).Interior.Color = RGB(192, 192, 192)
If Cells(iavntDaten1 + iavntSuchwert1 - 1, 13) < 3 Then Cells(iavntDaten1 + iavntSuchwert1 - 1, 13) = Cells(iavntDaten1 + iavntSuchwert1 - 1, 13) + 1
blnFund = False
Else
Set rngFund = Range(rngDaten.Rows(1), rngDatenLastRow).Find(vntSuchwert, , xlValues, xlWhole)
If Not rngFund Is Nothing Then
If rngFund.Interior.Color <> RGB(192, 192, 192) Then
rngFund.Interior.Color = vbYellow
If Cells(rngFund.Row, 13) < 3 Then Cells(rngFund.Row, 13) = Cells(rngFund.Row, 13) + 1
End If
Set rngDatenLastRow = Nothing
Set rngSuchwert = Nothing
End Sub
Public Function LetzteBeschriebeneZeile(ByRef rngBereich As Range) As Long
On Error Resume Next
LetzteBeschriebeneZeile = rngBereich.Find("*", , xlFormulas, xlWhole, xlByRows, xlPrevious).Row
End Function
Nach Ausführung des obigen Codes folgenden ausführen:
Code:
Sub zählen()
Dim i As Long, j As Long, pp As Long, k As Long
Dim lngZd As Long, lngZZ
Dim merkZ As Long
Dim anzahlDreier As Long
Dim strgSammlung As String
Dim rngB As Range, rngC As Range
lngZd = LetzteBeschriebeneZeile(Range("D:I"))
Columns("AN").ClearContents
anzahlDreier = Application.CountIf(Columns("M"), 3)
If anzahlDreier = 0 Then Exit Sub
merkZ = Application.Match(3, Columns("M"), 0)
k = 1
Application.ScreenUpdating = False
For pp = 1 To anzahlDreier
lngZZ = Application.Match(3, Range(Cells(k, 13), Cells(lngZd, 13)), 0)
Set rngB = Range("D1:I" & lngZZ + k - 2)
For i = 1 To lngZZ + k - 1
For j = 15 To 26
If Cells(i, j) <> "" Then
Set rngC = rngB.Find(Cells(i, j), , xlValues, xlWhole)
If Not rngC Is Nothing Then
If rngC.Interior.ColorIndex = xlColorIndexNone Then
If InStr(strgSammlung, Cells(i, j)) = 0 Then strgSammlung = strgSammlung & "#" & rngC
Else
If InStr(strgSammlung, Cells(i, j)) Then strgSammlung = Replace(strgSammlung, Cells(i, j) & "#", "")
End If
Else
If InStr(strgSammlung, Cells(i, j)) = 0 Then strgSammlung = strgSammlung & "#" & Cells(i, j)
End If
End If
Next j
Next i
If UBound(Split(strgSammlung, "#")) > 0 Then Cells(lngZZ + k - 1, 40) = UBound(Split(strgSammlung, "#"))
k = lngZZ + 1
Next pp
Range(Cells(merkZ, 4), Cells(lngZd, 9)).Clear
Columns("M").Clear
Application.ScreenUpdating = True
End Sub
Public Function LetzteBeschriebeneZeile(ByRef rngBereich As Range) As Long
On Error Resume Next
LetzteBeschriebeneZeile = rngBereich.Find("*", , xlFormulas, xlWhole, xlByRows, xlPrevious).Row
End Function
Gruß Atilla
Folgende(r) 1 Nutzer sagt Danke an atilla für diesen Beitrag:1 Nutzer sagt Danke an atilla für diesen Beitrag 28 • Angelina
anbei hab ich hoffentlich die fertige Version.
Ich habe das Makro schon dem Button AN Zählen zugewiesen.
Zumindest der code zum Löschen der Daten im Bereich D:I ist auch drin, ich weiß nach Deinem Video nur nicht, wieso ich löschen soll, wo Du doch am Ende den Ausgangszustand wiederherstellst. Zur Bewertung ist das Löschen jedenfalls nicht nötig, es werden nur die jeweils bis zur Zeile mit den 3 zugehörigen Bereiche oberhalb ausgezählt.
Die Frage nach der 12 und der 5 in AM ist mit dem Video allerdings nicht beantwortet. In der Zählung für AN 8 ist sie nun draußen bzw. wird automatisch als offen bewertet, egal, was da an zwölfen im Bereich D:I oder auch steht und gefärbt ist oder nicht. Ebenso die 16 aus Zeile 5. Würde z.B. in O 6 oder später noch eine 12 stehen, würde es wieder anders aussehen. Aber vielleicht kann so eine Konstellation auch nicht passieren. Ich tue ja die Zahlen von hinten - also von unten - aufsammeln und auch nur einfach und nicht doppelt.
Bei der Zählung für AN 3 wird die 12 hingegen berücksichtigt, da keine gefärbte in D1:I2 vorhanden ist, ist sie aber auch offen.
Schaue einfach mal mit unterschiedlichen Daten, ob die Ergebnisse passen.
. \\\|/// Hoffe, geholfen zu haben. ( ô ô ) Grüße, André aus G in T ooO-(_)-Ooo (Excel 97-2019+365)
Folgende(r) 1 Nutzer sagt Danke an schauan für diesen Beitrag:1 Nutzer sagt Danke an schauan für diesen Beitrag 28 • Angelina
Sub zählen()
Dim i As Long, j As Long, pp As Long, k As Long
Dim lngZd As Long, lngZZ
Dim merkZ As Long
Dim anzahlDreier As Long
Dim strgSammlung As String
Dim rngB As Range, rngC As Range
lngZd = LetzteBeschriebeneZeile(Range("D:I"))
Columns("AN").ClearContents
anzahlDreier = Application.CountIf(Columns("M"), 3)
If anzahlDreier = 0 Then Exit Sub
merkZ = Application.Match(3, Columns("M"), 0)
k = 1
Application.ScreenUpdating = False
For pp = 1 To anzahlDreier - 1
lngZZ = Application.Match(3, Range(Cells(k, 13), Cells(lngZd, 13)), 0)
Set rngB = Range("D1:I" & lngZZ + k - 2)
For i = 1 To lngZZ + k - 1
For j = 15 To 26
If Cells(i, j) <> "" Then
Set rngC = rngB.Find(Cells(i, j), , xlValues, xlWhole)
If Not rngC Is Nothing Then
If rngC.Interior.ColorIndex = xlColorIndexNone Then
If InStr(strgSammlung, Cells(i, j)) = 0 Then strgSammlung = strgSammlung & "#" & rngC
Else
If InStr(strgSammlung, Cells(i, j)) Then strgSammlung = Replace(strgSammlung, "#" & Cells(i, j), "")
End If
Else
If InStr(strgSammlung, Cells(i, j)) = 0 Then strgSammlung = strgSammlung & "#" & Cells(i, j)
End If
End If
Next j
Next i
If UBound(Split(strgSammlung, "#")) > 0 Then Cells(lngZZ + k - 1, 40) = UBound(Split(strgSammlung, "#"))
k = k + lngZZ + 1
Next pp
' Range(Cells(merkZ, 4), Cells(lngZd, 9)).Clear
' Columns("M").Clear
Application.ScreenUpdating = True
End Sub
Public Function LetzteBeschriebeneZeile(ByRef rngBereich As Range) As Long
On Error Resume Next
LetzteBeschriebeneZeile = rngBereich.Find("*", , xlFormulas, xlWhole, xlByRows, xlPrevious).Row
End Function
Das Löschen habe ich auskommentiert.
Gruß Atilla
Folgende(r) 1 Nutzer sagt Danke an atilla für diesen Beitrag:1 Nutzer sagt Danke an atilla für diesen Beitrag 28 • Angelina