Delete duplicate data in Excel

Source: Internet
Author: User

Please read and modify the relevant data carefully.

1. Open Excel with duplicate data

2, ALT+F11 open the Macro editor

3, left double click: ThisWorkBook

4, paste into the following code and run can:

Sub Delete duplicate data ()
' Delete duplicate data from Col column
' This example deletes the duplicate data in column A (starting from A2 cell) in an Excel table titled Sheet1
application.screenupdating = False
' Can modify the bottom of the following three lines according to the actual situation
Dim sheetscaption as String:sheetscaption = "Sheet1"
Dim Col as String:col = "A"
Dim StartRow as Integer:startrow = 2
' The following do not need to be modified
Dim Endrow as Integer:endrow = Sheets (sheetscaption). Range (Col & "65536"). End (Xlup). Row
Dim count_1 as Integer:count_1 = 0
Dim count_2 as Integer:count_2 = 0
Dim i as Integer:i = StartRow
With Sheets (sheetscaption)
Todo
count_1 = count_1 + 1
For j = StartRow to I-1
If. Range (Col & i) =. Range (Col & j) Then
Count_1 = Count_1-1
. Range (Col & i). Entirerow.delete
Endrow = Sheets (sheetscaption). Range (Col & "65536"). End (Xlup). Row
i = I-1
Count_2 = count_2 + 1
Exit for
End If
Next
i = i + 1
Loop While I < Endrow + 1
End With
MsgBox "Total" & count_1 & "Data not duplicated"
MsgBox "Delete" & count_2 & "Stripe duplicate data"
application.screenupdating = True
End Sub

5, press F5 key to run can

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.