Вы находитесь на странице: 1из 1

Private Sub CommandButton1_Click()

'Last Row Address for book3


Book2LastRowAddress =
Workbooks("book3").Sheets("Sheet1").Range("AG1").SpecialCells(xlCellTypeLastCell).A
ddress
'Last Row Adress for book4
Book4LastRowAddress =
Workbooks("book4").Sheets("Sheet1").Range("AG1").SpecialCells(xlCellTypeLastCell).A
ddress

LastRowBook3 = ""
LastRowBook4 = ""

'Last Row Number for book3


For i = Len(Trim(Book3LastRowAddress)) To 1 Step -1
If Mid(Book3LastRowAddress, i, 1) <> "$" Then
LastRowBook3 = Mid(Book3LastRowAddress, i, 1) & LastRowBook3
Else
Exit For
End If
Next i

'Last Row Number for book4


For i = Len(Trim(Book4LastRowAddress)) To 1 Step -1
If Mid(Book4LastRowAddress, i, 1) <> "$" Then
LastRowBook4 = Mid(Book4LastRowAddress, i, 1) & LastRowBook4
Else
Exit For
End If
Next i

'Final Comparison for duplicate Records


For i = 1 To Val(LastRowBook3)
For j = 1 To Val(LastRowBook4)

'Compare values and delete cell or row whatever is required


If Workbooks("book3").Sheets("Sheet1").Range("AG" & i).Value = _
Workbooks("book4").Sheets("Sheet1").Range("AG" & j).Value Then

'Your Code here to delete cells or row...

End If

Next j
Next i
End Sub

Вам также может понравиться