|
几经周折,终于调试成功,,呵呵,好高兴呀!
Sub zaizhitianshu()
Dim objcn As New ADODB.Connection
Dim sql As String
Dim sql2 As String
Sheet2.Cells.Clear
Sheet2.[a1:c1] = Array("工号", "姓名", "天数")
objcn.Open "provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data source= " & ThisWorkbook.FullName
sql = "select distinct 日期 as 日期,工号 as 工号, 姓名 as 姓名 from [sheet1$] group by 工号,姓名,日期"
sql2 = "select 工号, 姓名,count(日期) as 天数 from (" & sql & ") group by 工号,姓名"
Sheet2.[A2].CopyFromRecordset objcn.Execute(sql2)
objcn.Close
Set objcn = Nothing
Sheet2.Activate
End Sub
具体情况附件。 |
|