Tuesday, January 17, 2017

Delete Duplicate Data in Excel


Delete Duplicate Data in Excel Using VBA Code

Steps

01.Place Command Button on Excel Sheet as shown in Figure 01

Figure 01

02.Goto VBA Mode as shown in Figure 02


 Figure 02

03.Then type following coding under the Command Button Click Event 

Private Sub CommandButton1_Click()

Dim toAdd As Boolean, uniqueNumbers As Integer, i As Integer, j As Integer

Cells(1, 2).Value = Cells(1, 1).Value

uniqueNumbers = 1
toAdd = True

For i = 2 To 1000


    For j = 1 To uniqueNumbers
        If Cells(i, 1).Value = Cells(j, 2).Value Then
            toAdd = False
        End If
    Next j
        
    If toAdd = True Then
        Cells(uniqueNumbers + 1, 2).Value = Cells(i, 1).Value
        uniqueNumbers = uniqueNumbers + 1
    End If
    
    toAdd = True
 
Next i
End Sub

Screen Shot is as follows



 04.Finally Click Excel Icon in VBA mode then enter sample duplicate items in relevant sheet and see what happens.

See Final Screen Shot


No comments:

Post a Comment