|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
请测试- Sub Macro1()
- Dim cnn As Object, SQL$, s$
- Set cnn = CreateObject("adodb.connection")
- cnn.Open "provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data source=" & ThisWorkbook.FullName
- s = "select a.* from [设计部$] a inner join (select 姓名,刷卡日期,min(刷卡时间) as new_time from [设计部$] group by 姓名,刷卡日期) b on a.姓名=b.姓名 and a.刷卡日期=b.刷卡日期 and a.刷卡时间=b.new_time"
- SQL = "select 人员编号,登记号码,姓名,刷卡日期,刷卡时间,签到方式,设备编号,上下班标志,操作员,操作日期,备注,(select count(姓名) from [设计部$] where 姓名=b.姓名 and 刷卡日期=b.刷卡日期 group by 姓名,刷卡日期) from (" & s & ") b"
- Cells.ClearContents
- [a1:l1] = Array("人员编号", "登记号码", "姓名", "刷卡日期", "刷卡时间", "签到方式", "设备编号", "上下班标志", "操作员", "操作日期", "备注", "每天打卡数次")
- [a2].CopyFromRecordset cnn.Execute(SQL)
- cnn.Close
- Set cnn = Nothing
- End Sub
复制代码 |
|