您可以在「數據」選項卡中使用「刪除重複」應用程序。首先,複製A列,粘貼到B列中。然後選擇Data - > Remove Duplicates並選擇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
式
=COUNTIF(A:A,A2)
和過濾器的List1是包含要在其上操作的值範圍的*姓名*。在那個例子中,List1引用單元格A2:A20。對於新列表,您只需重新定義範圍即可。 –@EmacsUser,我對'CountIf'有些熟悉,第一個參數是範圍,第二個參數是要查找的表達式 - 爲什麼它是在上面這個例子中再次用作表達式的範圍? – OneFineDay
您可以指向該頁面中「如何使用此數組公式」工作的位置,因爲List1已使用4次,而且我不確定您指的是哪個表達式。 –