Friday, August 31, 2012

How to Trim Data and Delete Duplicate Records in Excel with VBA

VBA Macro to Delete Duplicate Records In a Specified Column in Excel
Sub Trim_Del()
Dim A As Integer
Dim B As Integer
Dim c As Integer
Dim d As Integer
Dim x As Integer

On Error GoTo Label:
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

Label:
End Sub

Thanks,Tamatam

No comments:

Post a Comment

Hi User, Thank You for visiting My Blog. Please post your genuine Feedback or comments only related to this Blog Posts. Please do not post any Spam comments or Advertising kind of comments which will be Ignored.

Featured Post from this Blog

How to compare Current Snapshot Data with Previous Snapshot in Power BI

How to Dynamically compare two Snapshots Data in Power BI Scenario: Suppose, we have a sample Sales data, which is stored with Monthly Snaps...

Popular Posts from this Blog