|
- Sub test0() '未改原来的,个人练习一下,供参考
-
- Dim ar(1 To 732, 1 To 200), br, Conn As Object
- Dim strConn As String, SQL As String, stComp As String
- Dim idx As Long, cnt As Long
- Dim posCol As Long, posRow As Long
-
- With Sheet2
- .Activate
- .UsedRange.Offset(1, 1).ClearContents
- End With
-
- Application.ScreenUpdating = False
- Application.Calculation = xlCalculationManual
-
- Set Conn = CreateObject("ADODB.Connection")
-
- If Application.Version < 12 Then
- strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;HDR=YES';Data Source="
- Else
- strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Excel 12.0;HDR=YES';Data Source="
- End If
- Conn.Open strConn & ThisWorkbook.FullName
-
- SQL = "SELECT 工号,姓名,DATEVALUE(日期) AS 日期,MIN(CDATE(日期)) AS MinTime,MAX(CDATE(日期)) AS MaxTime FROM [打卡记录$] WHERE LEN(日期) GROUP BY 工号,姓名,DATEVALUE(日期)"
- br = Conn.Execute(SQL).GetRows
-
- For idx = 0 To UBound(br, 2)
- posRow = Day(br(2, idx)) * 2 + 1
- If stComp <> br(0, idx) & br(1, idx) Then
- cnt = cnt + 1
- posCol = cnt * 2 - 1
- stComp = br(0, idx) & br(1, idx)
- ar(1, posCol) = br(0, idx)
- ar(2, posCol) = br(1, idx)
- End If
- ar(posRow, posCol) = br(3, idx)
- ar(posRow + 1, posCol) = br(4, idx)
- Next
-
- Range("B2").Resize(posRow + 1, cnt * 2) = ar
-
- Conn.Close
- Set Conn = Nothing
-
- Application.Calculation = xlCalculationAutomatic
- Application.ScreenUpdating = True
- Beep
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|