|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
用你得数据测试过,在我的电脑上,运行大概2分钟左右
Option Explicit
Sub a()
Dim WB As Workbook, F$, i&, j%, m%
Dim cnn, sql$, arr, TIM, brr(1 To 2)
TIM = Timer
Application.ScreenUpdating = False
brr(1) = "erp订单1.xlsx"
brr(2) = "erp订单2.xlsx"
Set cnn = CreateObject("adodb.connection")
cnn.Open "DRIVER=SQLite3 ODBC Driver; Database=:memory:"
sql = "CREATE TABLE T1(编号)"
cnn.Execute sql
sql = "CREATE TABLE T2(编号)"
cnn.Execute sql
F = ThisWorkbook.Path & "\srm订单.xls"
Set WB = Workbooks.Open(F)
For m = 1 To WB.Sheets.Count
arr = Sheets(m).[A1].CurrentRegion
For i = 1 To UBound(arr)
sql = "INSERT INTO T2 VALUES('" & arr(i, 1) & "')"
cnn.Execute sql
Next
Next
WB.Close 0
For j = 1 To 2
F = ThisWorkbook.Path & "\" & brr(j)
Set WB = Workbooks.Open(F)
For m = 1 To Sheets.Count
arr = WB.Sheets(m).[A1].CurrentRegion
For i = 2 To UBound(arr)
sql = "INSERT INTO T1 VALUES('" & arr(i, 1) & "')"
cnn.Execute sql
Next
WB.Close 0
Next
Next
With Sheet1
.Cells.Clear
.[A1] = "ERP有但SRM找不到"
.[D1] = "SRM有但ERP查不到"
sql = "select 编号 FROM T1 WHERE 编号 NOT IN (SELECT 编号 from T2)"
.Range("B2").CopyFromRecordset cnn.Execute(sql)
sql = "select 编号 FROM T2 WHERE 编号 NOT IN (SELECT 编号 from T1)"
.Range("E2").CopyFromRecordset cnn.Execute(sql)
End With
Set cnn = Nothing
Application.ScreenUpdating = True
Set cnn = Nothing
MsgBox Format(Timer - TIM, "0.00秒")
End Sub
需要下载一个sqlite odbc
https://www.ch-werner.de/sqliteodbc/
|
评分
-
1
查看全部评分
-
|