|
- Sub test1()
- Dim Conn As Object, rs As Object, SQL As String, strConn As String, i As Long
- Set Conn = CreateObject("ADODB.Connection")
- If Application.Version < 12 Then
- strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source="
- Else
- strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source="
- End If
- Conn.Open strConn & ThisWorkbook.FullName
- SQL = "SELECT 车牌号码,入场时间 FROM [Sheet1$] WHERE HOUR(入场时间)=23 OR HOUR(入场时间)<6"
- SQL = "TRANSFORM COUNT(*) SELECT 车牌号码 FROM (" & SQL & ") GROUP BY 车牌号码 PIVOT DATEVALUE(入场时间)"
- Set rs = Conn.Execute(SQL)
- With Range("D1")
- .CurrentRegion.ClearContents
- For i = 0 To rs.Fields.Count - 1
- .Offset(0, i) = rs.Fields(i).Name
- Next
- .Offset(1).CopyFromRecordset rs
- End With
- Set rs = Nothing
- Conn.Close
- Set Conn = Nothing
- Beep
- End Sub
复制代码 |
评分
-
3
查看全部评分
-
|