Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1572to1576
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

Doppelte löschen

Doppelte löschen
16.08.2017 10:37:12
Struppie
Hallo zusammen
Ich möchte in Spalte A nach doppelten suchen. Die doppelten Einträge stehen immer direkt untereinander. Wenn ein Eintrag in Spalte A doppelt und in der Spalte L kein Eintrag ist, soll die gesamte Zeile in der kein Eintrag in Spalte L ist gelöscht werden. Dies soll bis zum Tabellenende geschehen.
Kann mir jemand helfen?
Gruss Klaus

5
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Doppelte löschen
16.08.2017 12:05:27
Werner
Hallo Struppi,
teste mal:
Option Explicit
Sub Doppelte_raus()
Dim loZeile As Long
Dim loSpalte As Long
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
With Worksheets("Tabelle1") 'Blatt ggf. anpassen
loZeile = .Cells(.Rows.Count, 1).End(xlUp).Row
loSpalte = .Cells(1, .Columns.Count).End(xlToLeft).Column
.Range(.Cells(2, loSpalte + 1), .Cells(loZeile, loSpalte + 1)).FormulaLocal = _
"=WENN(UND(ZÄHLENWENNS(A:A;A2)>1;L2="""");1;"""")"
.Range(.Cells(2, loSpalte + 1), .Cells(loZeile, loSpalte + 1)).Value = _
.Range(.Cells(2, loSpalte + 1), .Cells(loZeile, loSpalte + 1)).Value
.Sort.SortFields.Clear
.Sort.SortFields.Add Key:=.Range(.Cells(2, loSpalte + 1), .Cells(loZeile, loSpalte + 1)) _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With .Sort
.SetRange Range(Cells(2, 1), Cells(loZeile, loSpalte + 1))
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.Apply
End With
loZeile = .Cells(.Rows.Count, loSpalte + 1).End(xlUp).Row
If loZeile > 1 Then
.Range(.Cells(2, 1), .Cells(loZeile, loSpalte + 1)).EntireRow.Delete
Else
MsgBox "Keine Doppler vorhanden"
End If
End With
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
Da von deiner Seite keine weiteren Angaben bin ich davon ausgegangen, dass in Zeile 1 Überschriften vorhanden sind und dein eigentlicher "Datenbereich" ab Zeile 2 beginnt.
Gegebenenfalls müsste nach Durchlauf des Codes der Datenbestand wieder nach Spalte A sortiert werden.
Gruß Werner
Anzeige
AW: Doppelte löschen
16.08.2017 13:17:27
Struppie
Hallo Werner
Funktioniert einwandfrei.
Vielen Dank
Gruss Klaus
AW: Doppelte löschen
16.08.2017 13:37:03
Werner
Hallo Struppi,
nimm besser den Code. Da habe ich am Anfang noch nach Spalte A sortiert (zur Sicherheit, funktioniert nämlich nur, wenn die Doppler jweils direkt aufeinander folgen) und am Ende wird auch noch mal nach Spalte A sortiert.
Option Explicit
Sub Doppelte_raus()
Dim loZeile As Long
Dim loSpalte As Long
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
With Worksheets("Tabelle1")
loZeile = .Cells(.Rows.Count, 1).End(xlUp).Row
loSpalte = .Cells(1, .Columns.Count).End(xlToLeft).Column
.Sort.SortFields.Clear
.Sort.SortFields.Add Key:=Range("A2:A" & loZeile), SortOn:=xlSortOnValues _
, Order:=xlAscending, DataOption:=xlSortNormal
With .Sort
.SetRange Range(Cells(2, 1), Cells(loZeile, loSpalte))
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
.Range(.Cells(2, loSpalte + 1), .Cells(loZeile, loSpalte + 1)).FormulaLocal = _
"=WENN(UND(A2=A1;L2="""");1;"""")"
.Range(.Cells(2, loSpalte + 1), .Cells(loZeile, loSpalte + 1)).Value = _
.Range(.Cells(2, loSpalte + 1), .Cells(loZeile, loSpalte + 1)).Value
.Sort.SortFields.Clear
.Sort.SortFields.Add Key:=.Range(.Cells(2, loSpalte + 1), .Cells(loZeile, loSpalte + 1)) _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With .Sort
.SetRange Range(Cells(2, 1), Cells(loZeile, loSpalte + 1))
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.Apply
End With
loZeile = .Cells(.Rows.Count, loSpalte + 1).End(xlUp).Row
If loZeile > 1 Then
.Range(.Cells(2, 1), .Cells(loZeile, loSpalte + 1)).EntireRow.Delete
loZeile = .Cells(.Rows.Count, 1).End(xlUp).Row
.Sort.SortFields.Clear
.Sort.SortFields.Add Key:=Range("A2:A" & loZeile), SortOn:=xlSortOnValues _
, Order:=xlAscending, DataOption:=xlSortNormal
With .Sort
.SetRange Range(Cells(2, 1), Cells(loZeile, loSpalte))
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Else
MsgBox "Keine Doppler vorhanden"
End If
End With
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
Gruß Werner
Anzeige
AW: Doppelte löschen
16.08.2017 12:40:20
fcs
Hallo Klaus,
sollte mit folgendem Makro funktionieren
Gruß
Franz
Sub DoppelteWeg_2()
Dim wks As Worksheet
Dim Zeile As Long, Zeile_L As Long, StatusCalc As Long
Dim Zeile_1 As Long, Zeile_2 As Long, Z As Long
Dim varWert, bolGeloescht As Boolean
Set wks = ActiveSheet
'Makrobremsen lösen
With Application
.ScreenUpdating = False
StatusCalc = .Calculation
.Calculation = xlCalculationManual
End With
With wks
Zeile_L = .Cells(.Rows.Count, 1).End(xlUp).Row
Zeile_1 = 1
Zeile_2 = Zeile_1
varWert = .Cells(1, 1).Value
bolGeloescht = False
For Zeile = 2 To Zeile_L + 1
If .Cells(Zeile, 1).Value  varWert Then
If Zeile_2 = Zeile_1 Then
'Werte in Spalte A kommt nur einmal vor
Else
'Anzahl Leerzellen in Spalte L prüfen
If Application.WorksheetFunction.CountIf( _
.Range(.Cells(Zeile_1, 12), .Cells(Zeile_2, 12)), "") = _
(Zeile_2 - Zeile_1 + 1) Then
'Alle Zeilen in Spalte L zum Wert in Spalte A sind leer
Zeile_1 = Zeile_1 + 1
End If
For Z = Zeile_1 To Zeile_2
If .Cells(Z, 12).Text = "" Then
.Cells(Z, 1).ClearContents
bolGeloescht = True
End If
Next
End If
varWert = .Cells(Zeile, 1).Value
Zeile_1 = Zeile
End If
Zeile_2 = Zeile
Next
If bolGeloescht = True Then
.Range(.Cells(1, 1), .Cells(Zeile_L, 1)).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End If
End With
'Makrobremsen zurücksetzen
With Application
.ScreenUpdating = True
.Calculation = StatusCalc
End With
End Sub

Anzeige
AW: Doppelte löschen
16.08.2017 13:07:02
Niclaus
Aller (guten) Dinge sind drei:
Sub Zeilenweg()
Dim lz As Long, i As Long, zw$
Application.ScreenUpdating = False
lz = Cells(Rows.Count, 1).End(xlUp).Rows.Row
For i = lz To 1 Step -1
zw = Cells(i, 1).Value
If Application.WorksheetFunction.CountIf(Range("A:A"), zw) > 1 _
And IsEmpty(Cells(i, 12)) Then
Rows(i).Delete
End If
Next i
Application.ScreenUpdating = True
End Sub
Grüsse Niclaus

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige