if any complete row is completely same with any other row in a sheet then delete the duplicate data

if any complete row  is completely same with any other row in a sheet then delete the duplicate data
see sheet2 for the result that I need
this highlighted colour is only for understanding purpose
i have to do this by vba
Book2.xlsm
Avinash SinghAsked:
Who is Participating?
 
Subodh Tiwari (Neeraj)Connect With a Mentor Excel & VBA ExpertCommented:
Please give this a try...
Sub DeleteDuplicateRows()
Dim lr As Long, lc As Long, i As Long
Dim x, dict
Dim str As String
Dim delRng As Range

Application.ScreenUpdating = False
lr = Cells(Rows.Count, 1).End(xlUp).Row
Set dict = CreateObject("Scripting.Dictionary")

For i = 1 To lr
    lc = Cells(i, Columns.Count).End(xlToLeft).Column
    x = Range("A" & i, Cells(i, lc)).Value
    If IsArray(x) Then
        str = Join(Application.Index(x, 1, 0), ",")
    Else
        str = x
    End If
    If Not dict.exists(str) Then
        dict.Item(str) = ""
    Else
        If delRng Is Nothing Then
            Set delRng = Cells(i, 1)
        Else
            Set delRng = Union(delRng, Cells(i, 1))
        End If
    End If
Next i
If Not delRng Is Nothing Then delRng.EntireRow.Delete
Application.ScreenUpdating = True
End Sub

Open in new window

0
 
ShumsDistinguished Expert - 2017Commented:
Hi Avinash,

Try below quick VBA without loop:
Sub DelDup()
Dim Ws As Worksheet
Dim LRow As Long
Dim LCol As Integer
Set Ws = Worksheets("Sheet1")
LRow = Ws.UsedRange.Rows.Count
LCol = Ws.Cells.Find(What:="*", After:=Ws.Range("A1"), SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column + 1
Application.ScreenUpdating = False
With Ws.Range("A1:A" & LRow)
    .AdvancedFilter xlFilterInPlace, Unique:=True
    .SpecialCells(xlCellTypeVisible).Offset(0, LCol - 1).Value = 1
    On Error Resume Next
    Ws.ShowAllData
    Ws.Columns(LCol).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    Err.Clear
End With
Ws.Columns(LCol).Clear
Application.ScreenUpdating = True
End Sub

Open in new window

Kindly note you need to have header column to execute above VBA
Check in attached...
AvinashSingh_DeleteDuplicates.xlsm
1
 
Avinash SinghAuthor Commented:
Thnx Neeraj sir for ur great support  and thnx alot for giving ur precious time to this post
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome Avinash!

Please remember to recognize the answers and queries posted other than the accepted answer also.
Experts devote their time in order to assist you and it's not fair when you don't respond to them properly.
Tell them politely why other solutions didn't work for you and why did you choose a specific answer as an accepted answer. That's a good habit and you will always get response of all the experts in your future questions. And if more than one answers work for you exactly as per your requirement, don't forget to split the points in that case.
0
 
Avinash SinghAuthor Commented:
Ok Neeraj sir in future i will not repeat this mistake again
1
 
Avinash SinghAuthor Commented:
Thnx shums sir for giving ur precious time to this post by mistakely i forgot to thnx u bcoz i just wake up in the morning and opened my pc and saw the solution actually i wasn't fresh that's why i forgot to thnx u
0
 
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Thanks Avinash!
0
All Courses

From novice to tech pro — start learning today.