- 帖子
- 354
- 主題
- 5
- 精華
- 0
- 積分
- 387
- 點名
- 0
- 作業系統
- windows7
- 軟體版本
- vba,vb,excel2007
- 閱讀權限
- 20
- 性別
- 男
- 註冊時間
- 2017-1-8
- 最後登錄
- 2024-8-2
 
|
- Sub t5()
- i = Split("Provider=Microsoft.,Jet.OLEDB.4,.0;Extended Properties=Excel ,8,.0;Data Source=", ",")
- If Application.Version > 12 Then i(1) = "ACE.OLEDB.12": i(3) = 12
- Set cn = CreateObject("adodb.connection"): cn.Open Join(i, "") & ThisWorkbook.FullName
- Set S1 = Sheet1: Set s2 = Sheet2: S1.[B7:AA9999].ClearContents:
- f = " from [資料$B4:I] "
- S1.[B7].CopyFromRecordset cn.Execute("select distinct 日期,星期 " & f)
- S1.[P7].CopyFromRecordset cn.Execute("select distinct 日期,星期 " & f)
- p = Split("select b.c from [工作表2$B6:B] as a left join (;;) as b on a.日期=b.日期 ", ";")
- For Each Z In S1.[d6:L6]
- p(1) = "select 日期,星期,count(入口) as c " & f & " where 入口 = '" & Z.Value & "' group by 日期,星期,入口"
- Z.Offset(1, 0).CopyFromRecordset cn.Execute(Join(p, ""))
- x = x & "+ iif(IsNull(" & Z.Value & "),0," & Z.Value & ") "
- Next
- S1.[M7].CopyFromRecordset cn.Execute("select " & Mid(x, 2, 9999) & " from [工作表2$D6:L]")
- For Each Z In S1.[R6:Z6]
- p(1) = "select 日期,星期,count(出口) as c " & f & " where 出口 = '" & Z.Value & "' group by 日期,星期,出口"
- Z.Offset(1, 0).CopyFromRecordset cn.Execute(Join(p, ""))
- Next
- S1.[AA7].CopyFromRecordset cn.Execute("select " & Mid(x, 2, 9999) & " from [工作表2$R6:Z]")
- End Sub
複製代碼 |
|