excel表格中,匹配关键字可以找出两个表格数据的相同值并进行分析与计算。通常有两种方法:
1 公式法:
比如在sheet1的A列,需要查找sheet2的B列在不在A列里面,那么在Sheet2的C列就可以写如下公式:
=vlookup(B1,sheet1!A:A,1,0)
sheet1的数据:
sheet2的数据与公式
途中#N/A就是没有找到,未匹配。
方法二:通过vba代码来查找并上色:
Sub filter()
Dim s1 As Variant
Dim i, j As Integer
Dim foundRange As Range
Application.ScreenUpdating = False
s1 = Sheet2.Range("B1:B180").Value
For i = 1 To UBound(s1, 1)
Set foundRange = Sheet1.Range("B1:B20357").Find(What:=s1(i, 1), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext)
If Not foundRange Is Nothing Then
Sheet1.Cells(foundRange.Row, 2).EntireRow.Interior.Color = rgbRed
Else
MsgBox s1(i, 1) & "并未在sheet1中找到", 64
End If
Next i
Application.ScreenUpdating = True
End Sub