die debug.print zeilen dienen der Kontrolle. die kannst du auskommentieren.
Sub
ZeilenLoeschen()
Dim
sh1
As
Object
, sh2
As
Object
, found, zeile
As
Long
, i
As
Long
, colcnt
As
Long
Dim
addr1
As
String
Set
sh1 = ThisWorkbook.Sheets(
"1"
)
Set
sh2 = ThisWorkbook.Sheets(
"2"
)
zeile = sh1.Cells(Rows.Count, 1).
End
(xlUp).Row
If
ActiveCell.Row > zeile
Then
Exit
Sub
zeile = ActiveCell.Row
Set
found = sh2.Range(
"A:A"
).Find(what:=sh1.Cells(zeile, 1), lookat:=xlWhole)
Debug.Print
"sh1 "
& found.Address
If
Not
found
Is
Nothing
Then
addr1 = found.Address
Do
colcnt = sh1.Cells(zeile, Columns.Count).
End
(xlToLeft).Column
If
colcnt <> sh2.Cells(found.Row, Columns.Count).
End
(xlToLeft).Column
Then
Exit
Do
For
i = 1
To
colcnt
If
sh1.Cells(zeile, i) <> sh2.Cells(found.Row, i)
Then
Exit
For
Next
If
i > colcnt
Then
Debug.Print
"sh2 ok "
& found.Address
sh1.Rows(zeile).Delete shift:=xlUp
sh2.Rows(found.Row).Delete shift:=xlUp
Exit
Sub
Else
Set
found = sh2.Range(
"A:A"
).FindNext(found)
Debug.Print
"sh2 not ok "
& found.Address
End
If
Loop
While
Not
found
Is
Nothing
End
If
End
Sub
gruß