若是你有兩列很長的數據,須要匹配他們是否相同,用excel能夠解決這個問題。sql
匹配不一樣的:oop
把你的兩列的數據放到A列和B列ui
按照截圖的步驟點擊到view 選項卡,點擊Macros,而後新建一個 把下面代碼拷貝進去spa
本文來自山貓的博客地址:http://shanmao.me/?p=1066 excel
Sub recipList()
Dim arr1, arr2, recipArr, x, i As Long
ReDim recipArr(i)
arr1 = Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row).Value
arr2 = Range("B1:B" & Cells(Rows.Count, "B").End(xlUp).Row).Value
For Each x In arr1
If IsError(Application.Match(x, arr2, 0)) Then
ReDim Preserve recipArr(i)
recipArr(i) = x
i = i + 1
End If
Next
For Each x In arr2
If IsError(Application.Match(x, arr1, 0)) Then
ReDim Preserve recipArr(i)
recipArr(i) = x
i = i + 1
End If
Next
For k = LBound(recipArr) To UBound(recipArr)
Range("C" & k + 1) = recipArr(k)
Next
End Sub
|
不須要保存,回到表格再點擊macros,點擊開始運行!code
一下子後就獲得相應的數據了。兩邊對比,得出不同的值,處理上萬條數據應該是沒問題的blog
還有一個匹配相同的:教程
根據上面步驟:代碼以下ip
Sub Find_Matches()
Dim CompareRange As Variant, x As Variant, y As Variant
' Set CompareRange equal to the range to which you will
' compare the selection.
Set CompareRange = Range("C1:C5")
' NOTE: If the compare range is located on another workbook
' or worksheet, use the following syntax.
' Set CompareRange = Workbooks("Book2"). _
' Worksheets("Sheet2").Range("C1:C5")
'
' Loop through each cell in the selection and compare it to
' each cell in CompareRange.
For Each x In Selection
For Each y In CompareRange
If x = y Then x.Offset(0, 1) = x
Next y
Next x
End Sub
|
這裏須要注意: 把你要對比的數據放在A列和C列。結果會出如今B列。ci
Set CompareRange = Range(「C1:C5″) 這裏的C1:C5就是比對從C1到C5.你能夠修改 C1:C5000,就是C1-C5000
比對以前你須要選中A列的數值。
這個效率比較慢,處理幾千條數據就會掛了。。。
這裏還有方法能夠比對。那就是把數據導入到sql,而後用sql語句對比。要懂sql的人才會哦。。
excel數據導入到sql教程能夠點擊這裏查看
這裏分享一個sql對比不一樣數據的sql語句:
SELECT yf.email FROM `key726` as yf WHERE yf.email not in (select `email` from `keydierzhouingame`)
匹配key726表裏面的email不在 keydierzhouingame 表中的結果。