假设我有一个Excel表格,其中有3列,分别是名称,年龄和数字。名称是A,B和C。年龄是10,11和12。数字是5,7和5。在“数字”列中,第三行中有重复的值5,该值已经出现在第一行中。我需要一种方法来删除存在重复值的行。如果值重复,则保留第一行。这意味着删除保留C的条目的方法。
这只是一个小场景,我需要对大量数据进行处理。
答案 0 :(得分:0)
Excel中的“数据”选项卡中有一个标准的功能区按钮,称为“删除重复项”。这应该完全满足您的要求:https://www.excel-easy.com/examples/remove-duplicates.html
答案 1 :(得分:0)
Jaskunwar,您似乎没有尝试过,否则您可能会找到n个解决方案,因为问题看起来非常简单。如果您还有其他问题,请描述。
按照亚历克斯建议,删除重复项将解决您的问题。您可以使用条件格式,数据透视,If公式来实现此目的。
答案 2 :(得分:0)
那呢? (选择所需范围)
Sub SpotUniques()
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Select range", xTitleId, WorkRng.address, Type:=8)
WorkRng.Select
With CreateObject("Scripting.Dictionary")
For Each cell In WorkRng
.Item(cell.Value) = .Item(cell.Value) + 1
If .Item(cell.Value) = 1 Then
With cell.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = RGB(255, 102, 0)
End With
End If
Next cell
End With
End Sub
答案 3 :(得分:0)
您可以尝试:
Option Explicit
Sub test()
Dim Lastrow As Long, Times As Long, i As Long
Dim rng As Range
Dim str As String
With ThisWorkbook.Worksheets("Sheet1")
'Find the last row of column A
Lastrow = .Cells(.Rows.Count, "C").End(xlUp).Row
'Start Loop from the lastrow to row 1 upside down
For i = Lastrow To 2 Step -1
'Give value to str
str = .Range("C" & i).Value
'Set the range you want to search
Set rng = .Range("C2:C" & Lastrow)
'Count how many times str appears in rng
Times = Application.WorksheetFunction.CountIf(rng, str)
'If it is appears more than one time and A & i value equal to C
If Times > 1 And .Range("A" & i).Value = "C" Then
.Rows(i).EntireRow.Delete
End If
Next i
End With
End Sub