|
- Sub test1() '
-
- Dim ar, br, cr, Conn As Object, Dict As Object
- Dim strConn As String, strSQL As String, p As String, f As String, s As String
- Dim i As Long, j As Long, pos As Long, x As Long, y As Long
-
- 'Application.ScreenUpdating = False
-
- s = "Excel 12.0;HDR=YES;Database="
- If Application.Version < 12 Then
- s = Replace(s, "12.0", "8.0")
- 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
-
- Set Dict = CreateObject("Scripting.Dictionary")
- Set Conn = CreateObject("ADODB.Connection")
- Conn.Open strConn & ThisWorkbook.FullName
-
- p = ThisWorkbook.Path & "\"
- f = Dir(p & "*.xls*")
-
- While Len(f)
- If p & f <> ThisWorkbook.FullName Then
- strSQL = "SELECT CDATE(时间) AS 时间,成交金额,新增粉丝数,评论次数 FROM [" & s & p & f & "].[分钟级$A1:I] WHERE 时间 IS NOT NULL"
- Dict.Add strSQL, vbNullString
- End If
- f = Dir
- Wend
- strSQL = "SELECT * FROM (" & Join(Dict.Keys, " UNION ALL ") & ") WHERE 时间 BETWEEN #[A]# AND #[B]#"
- Dict.RemoveAll
-
- With Range("G1").CurrentRegion
- .Offset(2, 1).ClearContents
- ar = .Value
- End With
- For i = 3 To UBound(ar)
- Dict.Add ar(i, 1), i
- Next
-
- br = Range("A1").CurrentRegion
- For i = 2 To UBound(br)
- If Dict.Exists(br(i, 3)) Then
- pos = Dict(br(i, 3))
- cr = Conn.Execute(Replace(Replace(strSQL, "[A]", CDate(br(i, 1))), "[B]", CDate(br(i, 2)))).GetRows
- ar(pos, 2) = ar(pos, 2) + DateDiff("N", cr(0, 0), cr(0, UBound(cr, 2)))
- For x = 0 To UBound(cr, 2)
- For y = 1 To UBound(cr)
- ar(pos, y + 2) = ar(pos, y + 2) + Val(Replace(cr(y, x), ChrW(165), ""))
- Next
- Next
- End If
- Next
-
- With Range("G1").CurrentRegion
- .Columns(2).NumberFormatLocal = "0分"
- .Value = ar
- End With
-
- Conn.Close
- Set Conn = Nothing
- Set Dict = Nothing
-
- Application.ScreenUpdating = True
- Beep
- End Sub
复制代码 |
评分
-
2
查看全部评分
-
|