Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 搜索不存在的数据_Excel - Fatal编程技术网

Excel 搜索不存在的数据

Excel 搜索不存在的数据,excel,Excel,我有两组数据范围。一个范围位于表1(8000行,6列),这是主范围,另一个范围位于表2(5000行,6列)。如何在新工作表(工作表3)上显示不在工作表2中但在工作表1中的其他3000行?我可以将其设置为宏,但首先,请告诉我这是否符合您的要求 这是我使用的样本数据,共三页 称为“主控”的第1页如下所示,从A1开始: Name Birthday Month Age Batman January 35 Superman

我有两组数据范围。一个范围位于表1(8000行,6列),这是主范围,另一个范围位于表2(5000行,6列)。如何在新工作表(工作表3)上显示不在工作表2中但在工作表1中的其他3000行?

我可以将其设置为宏,但首先,请告诉我这是否符合您的要求

这是我使用的样本数据,共三页

称为“主控”的第1页如下所示,从A1开始:

Name            Birthday Month     Age
Batman          January            35
Superman        March              32
Catwoman        April              37
Joker           June               28
Harley Quinn    September          33
Rorschach       July               35
Dr. Manhattan   August             41
Aquaman         October            22
Ms. Jupiter     October            23
Penguin         July               39
第二张:

Name            Birthday Month     Age
Batman          January            35
Superman        March              32
Catwoman        April              37
Joker           June               28
Harley Quinn    September          33
Rorschach       July               35
所以,正如你所看到的,我们需要将曼哈顿博士加入到(目前为空白)表3中

检查工作表2中没有的内容的一种快速方法是在主工作表中添加一个helper列,然后简单地计算每个记录在工作表2中显示的次数。在母版纸上,将此公式输入D2并向下复制,
=Countifs(Sheet2!$A:$A,A2,Sheet2!$B:$B,B2,Sheet2!$C:$C,C2)

这将给您留下记录在表2中显示的次数。当您看到“0”时,这意味着您需要将这些记录添加到工作表3:

就这样

注意:因为您有大量的行,所以可能会交替使用1和0。要快速确定哪些未包含在Sheet2中,只需按D列(“带标题”)对所有数据进行排序即可:

(注意:我最初选择了A1:D11范围,但由于我选择了“has headers”,Excel会将可见的选定范围删除一行。点击“OK”,所有“0”报告都在顶部,您可以将其添加到工作表3中


我可以把它做成一个宏,但是如果你能先让我知道它是如何为你工作的。谢谢

编辑:宏包括在内,请让我知道如果你需要任何调整

  Sub Find_Reports()
    Dim lastRow As Long, lastCol As Integer, missingLastRow As Integer
    ' Create variables for the master worksheet, the list wsht (which has SOME of the Master records), and missing WS which we will put the missing records
    Dim masterWS As Worksheet, listWS As Worksheet, missingWS As Worksheet
    Dim listWSName As String
Dim ws as Worksheet

Application.DisplayAlerts= false
For each ws in Sheets
     If ws.name = "Missing" then ws.delete
Next ws
Application.DisplayAlerts= True

    Set masterWS = Sheets("Master List") ' Change this to whatever your Master List sheet is called
    Set listWS = Sheets("Sheet2") ' same with Master, change this to whatever the second sheet (that has SOME of the data) is called
    listWSName = listWS.Name

    Sheets.Add.Name = "Missing"
    Set missingWS = Sheets("Missing")
    missingWS.Rows(1).Value = masterWS.Rows(1).Value
    missingLastRow = 2 'Start on row 2

    lastRow = masterWS.Cells(1, 1).End(xlDown).Row 'I am assuming you have NO gaps in your column A, if you do, uncomment and use the next line instead
    'lastRow = masterWS.UsedRange.Rows.Count

    lastCol = masterWS.Cells(1, 1).End(xlToRight).Column

    Dim countCol As Integer
    countCol = lastCol + 1 'We will add the COUNT formula to this column
    masterWS.Cells(1, countCol).Value = "Times included in " & listWSName
    With masterWS
        .Range(.Cells(2, countCol), .Cells(lastRow, countCol)).FormulaR1C1 = "=COUNTIFS(" & listWSName & "!C[-3],RC[-3]," & listWSName & "!C[-2],RC[-2]," & listWSName & "!C[-1],RC[-1])"
    End With

    'Now, we would add the rows with a "0" next to it in Master WS to the new "Missing" WS
    Dim i As Integer
    With masterWS
        For i = 2 To lastRow
            If .Cells(i, countCol).Value = 0 Then 'If there is no record, add to the missing WS
                missingWS.Range(missingWS.Cells(missingLastRow, 1), missingWS.Cells(missingLastRow, lastCol)).Value = _
                    .Range(.Cells(i, 1), .Cells(i, lastCol)).Value
                missingLastRow = missingLastRow + 1
            End If
        Next i
    End With


    End Sub

我有一些想法-你能发布一些示例数据吗?两张表中的数据类型是否相同?例如,Sheet1的标题是否与Sheet2相同?当然,这里有一个示例,我将其放在一起。是的,所有列标题都匹配。主控表列出了所有数据。第1部分仅列出了一些行。我希望第2部分显示不匹配的缺失行在第1部分中,但在Master中。例如,列为:“姓名”、“生日月份”、“年龄”母版将列出填写的10行数据。第1部分仅列出母版中列出的10行中的4行。我希望第2部分显示第1部分中未列出的10行中缺少的6行。但我不知道如何将此文件附加到此处。我已使用VBA代码进行了更新。如果有任何问题或不起作用,请告诉我!(如果这样做行得通的话,你能帮我标记一下答案吗?谢谢!)它添加了新的工作表,但它给了我一个“溢出”错误运行时错误6并指向代码:lastRow=masterWS.UsedRange.Rows.Count,我的列中没有任何空格,在该代码之前添加一个撇号,因为没有空格,您可以使用上面的一个。注意:我已更新了代码,因此如果“缺少的“”工作表已经存在。从技术上讲,您可以-但这是了解一些VBA和正在发生的事情的绝佳机会。注意,我还将最后一行的类型更改为LONG,而不是Integer。请重新复制所有代码并重试,让我知道发生了什么情况。很抱歉…它在:for I=2 to lastRow处给出了一个错误