我需要在列中获取所有重复项。该列目前已排序。我相信这需要是一个宏(可能是一个函数),所以它可以将重复的值添加到另一列。我想在A列中粘贴一系列单元格,并让B列给出重复项。示例如下。
A栏
SD1000023
SD1000024
SD1000024
SD1000025
SD1000026
SD1000026
SD1000027
然后我的专栏会有:
B栏
SD1000024
SD1000026
从here
我发现了这个,不知道如何根据我的需要修复它。我不理解list1
部分。
=INDEX(List1, MATCH(0, COUNTIF(C1:$C$1, List1)+IF(COUNTIF(List1, List1)>1, 0, 1), 0))
答案 0 :(得分:2)
您可以使用"删除重复项"应用程序在数据选项卡中。首先,复制A列,粘贴到B列中。然后选择Data - >删除重复项并选择B列(询问时不要延伸到A列)。然后单击"确定",这将为您提供唯一值列表。然后,在那些,看看哪些有重复,你可以(在C列),做" = Countif(B1,A:A)"查看列表中出现该值的次数。
这是一个应该让你前进的宏。请注意,我假设您有一个标题行,如果不是,您只需稍微调整一下:
Sub List_Duplicates()
Dim lastRow As Integer, dataCol As Integer, duplicateCol As Integer, lastUniqueRow As Integer
Dim dataRng As Range, dupRng As Range
Dim ws As Worksheet
Set ws = ActiveSheet
With ws
lastRow = .Cells(1, 1).End(xlDown).Row 'This assumes your Column A has no line breaks, if it does, comment this out and use below
'lastRow = .UsedRange.Rows.Count
dataCol = 1 'if your list of data, including duplicates, is in COlumn A
duplicateCol = 2 'where to put the duplicate number
Set dataRng = .Range(.Cells(2, dataCol), .Cells(lastRow, dataCol))
Set dupRng = .Range(.Cells(2, duplicateCol), .Cells(lastRow, duplicateCol))
'First, we will copy the Column A data to column B
dupRng.Value = dataRng.Value
'Now, remove duplicates from this
lastUniqueRow = .Cells(2, duplicateCol).End(xlDown).Row
dupRng.RemoveDuplicates Columns:=1, Header:=xlNo
'Evaluate the countif formula, and then leave duplicates in col. B
Dim i As Integer
For i = 2 To lastUniqueRow 'This will loop through our duplicate cells, and remove any that are not duplicates
If .Cells(i, duplicateCol).Row > lastUniqueRow Then Exit For
Debug.Print .Cells(i, duplicateCol).Value & " occurrs " & Evaluate(WorksheetFunction.CountIf(dataRng, .Cells(i, duplicateCol))) & " times."
If Evaluate(WorksheetFunction.CountIf(dataRng, .Cells(i, duplicateCol))) <= 1 Then
.Cells(i, duplicateCol).Value = ""
End If
Next i
dupRng.Select
dupRng.SpecialCells(xlCellTypeBlanks).Delete
End With
End Sub
如果您有任何疑问,请与我们联系!如果其他人对上述内容有任何意见或建议,请告诉我,以便我也可以学习:P
答案 1 :(得分:0)
这可能会有所帮助:
假设数据从A1开始,在B1中输入
{% extends "base.html" %}
{% load widget_tweaks %}
{% block content %}
<div class="container-fluid">
<!-----INPUT FORM------------------->
<form action="{% url 'incidents:index' %}" method="GET">
<div class="row">
<div class="form-group col-md-3">
<label>Date Incident Reported</label><br>
{{ form.incident_date_time_reported|add_class:"form-control"}}
{{ form.incident_date_time_reported.errors }}
</div>
<div class="form-group col-md-3">
<label>------</label>
<button type="submit" class="btn btn-primary btn-block">Search</button>
</div>
</div>
</form>
</div><!-----END OF BOOTSTAP CONTAINER FLUID----->
{% endblock %}
在B2中输入
=IF(A1 = A2, A1,"")
然后将此公式复制到剩下的B.这将导致重复的值恰好出现在B列中一次。然后,您可以复制它们并将它们作为值粘贴回原位,然后对结果进行排序以获得您想要收集到相邻单元格中的内容。
答案 2 :(得分:0)
重复项的条件格式列A.然后,此宏将标记B列中的所有重复项。
Sub dup()
Dim lastRow As Long
lastRow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row
For i = 1 To lastRow
If Cells(i, 1).DisplayFormat.Interior.Color <> 16777215 Then
Cells(i, 2) = "Dup"
End If
Next
End Sub
答案 3 :(得分:0)
在旁边的列中,您可以使用公式=COUNTIF(A:A,A2)
并过滤不等于1的任何内容