|
后台表1我增加了2列如下:
运行结果如下:
附件:
test.rar
(23.34 KB, 下载次数: 3)
代码:
- Sub test()
- Dim CNN As Object
- Set d = CreateObject("Scripting.Dictionary")
- Set CNN = CreateObject("adodb.connection")
- CNN.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='excel 12.0;hdr=yes;imex=1';Data Source=" & ThisWorkbook.FullName
- s1 = "select * from [操作表$a:a] where 对象 is not null "
- s2 = "select * from [后台表1$] where 对象 is not null "
- SQL = "select * from (" & s1 & ")a left join (" & s2 & ")b on a.对象=b.对象"
- With Sheets("操作表")
- .Range("d1:x10000").Clear
- .[d2].CopyFromRecordset CNN.Execute(SQL)
- .Columns(5).Delete
-
- xrr = Sheets("后台表1").UsedRange.Rows(1)
- .[d1].Resize(1, UBound(xrr, 2)) = xrr
- .[d1].Offset(0, UBound(xrr, 2)) = "状况"
- End With
- s3 = "select * from [后台表2$] where 数据 is not null "
- s4 = "select * from [后台表3$] where 数据 is not null "
- SQL = s3 & " union " & s4
- Set rst = CNN.Execute(SQL)
- arr = WorksheetFunction.Index(rst.GetRows, 0, 0)
- st = Join(arr, ",")
- CNN.Close: Set CNN = Nothing
- With Sheets("操作表")
- brr = .[d1].CurrentRegion
- For i = 2 To UBound(brr)
- For ii = 2 To UBound(brr, 2) - 1
- If InStr(st, brr(i, ii)) = 0 Or brr(i, ii) = "" Then d(brr(1, ii) & "无") = ""
- Next
- brr(i, UBound(brr, 2)) = IIf(d.Count = 0, "ok", Join(d.Keys, ","))
- d.RemoveAll
- Next
-
- crr = WorksheetFunction.Index(brr, 0, UBound(brr, 2))
- .[d1].Offset(0, UBound(xrr, 2)).Resize(UBound(brr), 1) = crr
- End With
- End Sub
复制代码
|
-
|