|
- Sub test0() '参与 仅供测试
- Dim Conn As Object, SQL As String
- Dim ar() As String, i As Long, wks As Worksheet
-
- Set Conn = CreateObject("ADODB.Connection")
- If Application.Version < 12 Then
- Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=" & ThisWorkbook.FullName
- Else
- Conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & ThisWorkbook.FullName
- End If
-
- For Each wks In Worksheets
- With wks
- If InStr(.Name, "工资") > 0 Or InStr(.Name, "物贴") > 0 Then
- i = i + 1
- ReDim Preserve ar(1 To i)
- ar(i) = "SELECT * FROM [" & .Name & "$A1:C" & .Cells(.Rows.Count, 1).End(xlUp).Row & "]"
- End If
- End With
- Next
-
- SQL = "SELECT 单位,身份证号,FIRST(姓名) AS 姓名 FROM (" & Join(ar, " UNION ALL ") & ") WHERE 单位[满足条件] GROUP BY 单位,身份证号"
- With Worksheets("汇总")
- .Range("G1").CurrentRegion.Offset(1).ClearContents
- .Range("G2").CopyFromRecordset Conn.Execute(Replace(SQL, "[满足条件]", "<>'广州'"))
- .Range("J2").CopyFromRecordset Conn.Execute(Replace(SQL, "[满足条件]", "='广州'"))
- End With
-
- Conn.Close
- Set Conn = Nothing
- Beep
- End Sub
复制代码 |
评分
-
3
查看全部评分
-
|