|
- Sub cop()
- Dim cnn As Object, SQL$, SQ$, Rs As Object, ar
- Dim i&, sht As Worksheet, d As Object
- Set cnn = CreateObject("ADODB.Connection")
- Set d = CreateObject("Scripting.Dictionary")
- cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Excel 12.0;HDR=yes;IMEX=1';Data Source=" & ThisWorkbook.FullName
- For Each sht In Worksheets
- If sht.Name <> "数据查询" Then
- SQL = "select * from [" & sht.Name & "$b3:l] where 姓名 is not null"
- d(SQL) = ""
- End If
- Next
- If d.Count Then
- SQL = Join(d.Keys, " UNION ALL ")
- SQ = "select 姓名 from [数据查询$b3:l] where 姓名 is not null"
- SQ = "select b.* from (" & SQ & ")a left join (" & SQL & ")b on b.姓名=a.姓名"
- Set Rs = cnn.Execute(SQ)
- End If
- With Worksheets("数据查询")
- .Activate
- .Range("c4:l15").ClearContents
- .Range("b4").CopyFromRecordset Rs
- End With
-
- cnn.Close
- Set cnn = Nothing
- Set Rs = Nothing
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|