ich habe aus dem Netz folgenden Code, den ich gern verstehen möchte.
Sub Vergleich()
Dim iRowA As Integer, iRowB As Integer
Dim iCol As Integer, iColor As Integer
Dim iRowC As Integer
Dim bln As Boolean, blnColor As Boolean
iRowA = 2 ' Beginn Zeile 2
iColor = 2 ' Farbe weiß
Do Until IsEmpty(Cells(iRowA, 1))
iRowB = iRowA + 1
Do Until IsEmpty(Cells(iRowB, 1))
For iCol = 1 To 3
If Cells(iRowA, iCol) Cells(iRowB, iCol) Then ' wenn Eintrag in der Zeile
bln = True
Exit For
End If
Next iCol
If bln = False Then
If blnColor = False Then
iColor = iColor + 1 ' rot
End If
If Cells(iRowB, 1).Interior.ColorIndex = _
xlColorIndexNone Then
If Cells(iRowA, 1).Interior.ColorIndex = _
xlColorIndexNone Then
With Worksheets("Doppelt")
iRowC = .Cells(Rows.Count, 1).End(xlUp).Row + 1 ' letzte Zeile?
.Range(.Cells(iRowC, 1), .Cells(iRowC, 3)).Value = _
Range(Cells(iRowB, 1), Cells(iRowB, 3)).Value
End With
End If
Range(Cells(iRowA, 1), Cells(iRowA, 3)). _
Interior.ColorIndex = iColor
Range(Cells(iRowB, 1), Cells(iRowB, 3)). _
Interior.ColorIndex = iColor
blnColor = True
End If
End If
iRowB = iRowB + 1
bln = False
Loop
blnColor = False
iRowA = iRowA + 1
Loop
End Sub
Ein paar Kommentare habe ich schon eingefügt, die aber nicht unbedingt richtig sind.
Der Sub markiert alle doppelten Einträge und markiert sie rot. Anschließend schreibt er die doppelten Werte in die Tabelle "Doppelt".
Ich möchte gern den Code verstehen, um ihn für meine Belange anzupassen.
Folgendes habe ich später vor:
Ich habe die Werte bei mir statt nur in einer Tabelle zusätzlich noch in einer UF bei einer Listbox eingelesen.Über einen Button sollen die doppelten Einträge in der Listbox gefiltert werden, um sie darin zu löschen.
Das ist die Zukunft...
Ich schicke trotzdem mal die Beispiel-Mappe. Es wäre super, wenn sich jemand mit seiner Hilfe am Projekt beteiligt.
https://www.herber.de/bbs/user/136417.xlsm
Vielen Dank.
LG
Peer