2017-02-21 55 views
-4

我有在Excel中两片:如何使用不规则的公因子比较excel中的两张纸?

表1:

Col1 Col2 
A 11 
B 22 
C 33 

表2:

Col1 Col2 
C  33 
A  00 
K  44 
Z  11 

我在Col1中使用一个共同的因素,在COL1一些值两片材进行比较Sheet1中可能不存在,反之亦然。 col1中的实体数量在两张纸上都不相同。如果存在一个共同因素,那么第2栏中相应的值可能在两张纸上都不相同。

我需要找出与这两张纸不同的值的共同因素。

回答

0

您可以简单地使用VLOOKUP来执行此功能。在表2中,突出显示所有数据,转到公式>名称管理器>新建并为其命名,例如数据。

然后在COL3表1使用这样的:

=IFERROR(VLOOKUP(A1,Data,2,0),"") 

然后,如果在表1 Col1中ROW1的值在表2 Col1中存在,它将在表1 COL3打印对应的值。如果它不存在,它将保持空白。只需将公式向下拖动到表单1中的所有单元格即可。

对于您的信息使用上述公式,如果A在Sheet 1 Cell A1中,Sheet 1 Cell A3将读取0,这是A in工作表2.单元格B3和C3将为空白,因为它们不在工作表2中。

如果这很有用,请打勾以接受答案。

0

您可以使用此

Option Explicit 

Sub main() 
    Dim sh1 As Worksheet: Set sh1 = Worksheets("Sheet") 
    Dim sh2 As Worksheet: Set sh2 = Worksheets("Sheet2") 
    Dim cell As Range 
    Dim nFounds As Long 

    With CreateObject("Scripting.Dictionary") 
     For Each cell In sh1.Range("A1", sh1.Cells(sh1.Rows.Count, 1).End(xlUp)) 
      .Item(cell.Value) = cell.Offset(, 1) 
     Next 
     If .Count > 0 Then 
      ReDim founds(1 To .Count) 
      For Each cell In sh2.Range("A1", sh2.Cells(sh2.Rows.Count, 1).End(xlUp)) 
       If .exists(cell.Value) Then 
        If .Item(cell.Value) <> cell.Offset(, 1) Then 
         nFounds = nFounds + 1 
         founds(nFounds) = cell.Value 
        End If 
       End If 
      Next 
      If nFounds > 0 Then 
       ReDim Preserve founds(1 To nFounds) 
       MsgBox "common factors with different values: " & vbCrLf & vbCrLf & Join(founds, vbCrLf) 
      Else 
       MsgBox "no common factors found" 
      End If 
     End If 
    End With 
End Sub