Friday, 31 August 2012

Excel VBA Macro To Trim Data And Delete Duplicate Records

Macro To Delete Duplicate Records In a Specified Column
Sub TrimDel()
Dim A As Integer
Dim B As Integer
Dim c As Integer
Dim d As Integer
Dim x As Integer

On Error GoTo TPR:

B = InputBox("Enter Column No. To Check For Duplicates:")

For A = 1 To 100
Cells(A, B).Offset(0, 1) = Application.Proper(Trim(Replace(Replace(Replace (LCase(Cells(A, B)),  ".", " "), ",", " "), "  ", " ")))

Next A

For c = 100 To 1 Step -1
For d = 100 To 1 Step -1
If d <> c Then

If Cells(d, B).Offset(0, 1) = Cells(c, B).Offset(0, 1) Then
x = x + 1

If x > 2 Then
Cells(c, B).Offset(0, 1).Delete shift:=xlUp
Application.ScreenUpdating = False

End If
End If
End If

Next d
Next c


End Sub

No comments:

Post a Comment

Hi User, Thank You for visiting My Blog. Please post your open Feedback only related to this Blog Posts. Please note that I cannot respond to the Anonymous Comments.

Subscribe to Blog Posts by Email

ExcelKingdom-Popular Posts