指示具有多个相应值的单元

我目前有一个Excel数据集,显示在不同时间销售的产品以及销售人员如何指定销售的产品类别。

Product# Product Class 10001 Hardware 20002 Software 30003 Misc. 10001 Hardware 10001 Software 20002 Software 10001 Hardware 30003 Misc. 

您会注意到产品#10001(应该被归类为“硬件”),销售人员错误地将其中一个销售指定为“软件”。

因此,如果我按产品#10001过滤,我将得到2个不同的产品类别。 我试图找出哪个产品#有超过1个产品类别的约30,000个不同的产品,以便它们可以被修复。

我怎样才能通过数据来表明哪些产品号码需要固定只有1个产品类?

我预计只有less数情况下存在这种多个类别的问题,所以一旦我能找出哪个产品#有问题,就可以手动修复。

谢谢!

您可以使用此公式=IF(COUNTIF($A$3:$A$1000,A3)-COUNTIFS($A$3:$A$1000,A3,$B$3:$B$1000,B3)>0,"Wrong","OK")在单元格C3 。 根据您的需要调整范围,并将公式拖动到底部。

在这里输入图像说明

您可以使用称为字典的对象。 字典有一个键和一个对应的值。 它存储密钥的方式被实现,以便快速查明字典中是否存在特定的密钥,这将有助于检查重复的产品代码。

为了简单起见(因为我在Excel中几乎没有VBA的经验),我假定要检查的数据在Sheet(1)的第1和第2列中:

 Option Explicit ' Add reference to get Dictionary: http://www.techbookreport.com/tutorials/vba_dictionary.html ' Excel VBA- Finding the last column with data: https://stackoverflow.com/a/11927387 Sub FindDuplicates() Dim dict As Dictionary Set dict = New Dictionary Dim ws As Worksheet Set ws = Sheets(1) Dim rLastCell As Range Set rLastCell = ws.Cells.Find(What:="*", After:=ws.Cells(1, 1), LookIn:=xlFormulas, LookAt:= _ xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False) Dim key As String Dim val As String Dim dupes As String Dim i As Long ' use maxFinds to limit the number of duplicates found Dim maxFinds As Integer maxFinds = 32 Dim nFound As Integer nFound = 0 For i = 1 To rLastCell.Row key = Cells(i, 1).Value val = Cells(i, 2).Value If dict.Exists(key) Then If dict(key) <> val Then dupes = dupes & "Row: " & i & " Class: " & val & vbCrLf nFound = nFound + 1 End If Else dict.Add key, val End If If nFound = maxFinds Then Exit For End If Next If nFound = 0 Then MsgBox ("No duplicates found.") Else MsgBox (dupes) End If End Sub 

字典对象不是内置于Excel的,因此您需要通过“工具”菜单 – >“引用…”添加对Microsoft脚本运行时的引用。

我创build了一个包含5万行的testing文件,并且有相当多的重复项,这就是为什么代码最终会限制find重复项的次数,所以你可以设置maxFinds = 10 ,然后再次运行macros再找十个,等等。 另外,如果有32个以上的人,那么他们不适合在消息框中。

它假定“Product Class”(或上面代码示例中第2列中的值)的第一次出现是正确的。

示例输出:

在这里输入图像说明

你可以使用这个数组公式(点击Ctrl + Shift + Enter一起)来找出哪一个需要照顾:

 =IF(IFERROR(VLOOKUP(A2,$A$1:A1,1,0),0)>0,IF(ISTEXT(VLOOKUP(A2&B2,$A$1:A1&$B$1:B1,1,0)),"","Dup"),"") 

cell C2公式并向下拖动。

然后只要用Dup做一个filter。 这应该适合你。