|
本帖最后由 跨越时空 于 2024-6-27 10:45 编辑
帮你写了上面部分,下面都是复制粘贴的事情。
Sub lztj()
Dim Conn As Object, rs As Object, SQL As String, strConn As String, CMonth%, Yday%
Set Conn = CreateObject("ADODB.Connection")
Sheet3.Activate
strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source="
Conn.Open strConn & ThisWorkbook.FullName
CMonth = Month(Date)
Yday = Day(Date - 1)
SQL1 = "SELECT COUNT(离职日期) AS 离职人数 FROM [Sheet2$A:D] WHERE MONTH(离职日期)=" & CMonth & "and 员工分类='衡阳分中心'"
SQL2 = "SELECT COUNT(离职日期) AS 离职人数 FROM [Sheet2$A:D] WHERE MONTH(离职日期)=" & CMonth & "and 员工分类='贵阳分中心'"
SQL3 = "SELECT COUNT(离职日期) AS 离职人数 FROM [Sheet2$A:D] WHERE MONTH(离职日期)=" & Yday & "and 员工分类='衡阳分中心'"
SQL4 = "SELECT COUNT(离职日期) AS 离职人数 FROM [Sheet2$A:D] WHERE MONTH(离职日期)=" & Yday & "and 员工分类='贵阳分中心'"
Set rs1 = Conn.Execute(SQL1)
Set rs2 = Conn.Execute(SQL2)
Set rs3 = Conn.Execute(SQL3)
Set rs4 = Conn.Execute(SQL4)
With Sheet3
.[D2].ClearContents
.[D2].CopyFromRecordset rs1
.[D3].ClearContents
.[D3].CopyFromRecordset rs2
.[C2].ClearContents
.[C2].CopyFromRecordset rs3
.[C3].ClearContents
.[C3].CopyFromRecordset rs4
End With
rs1.Close
Set rs1 = Nothing
rs2.Close
Set rs2 = Nothing
rs3.Close
Set rs3 = Nothing
rs4.Close
Set rs4 = Nothing
Conn.Close
Set Conn = Nothing
End Sub |
|