|
Sub limonet()
Dim Cn As Object, StrSQL$, i%, j%, Sht As Worksheet, Rst As Object
Set Cn = CreateObject("Adodb.Connection")
Cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & ThisWorkbook.FullName
For Each Sht In Worksheets
If Sht.Name Like "第*周" Then
For i = 1 To Sht.Range("A3").End(xlToRight).Column Step 3
StrSQL = StrSQL & " Union All Select #" & Sht.Cells(2, i) & "# as 日期,* From [" & Sht.Name & "$" & Sht.Cells(3, i).Resize(99, 3).Address(0, 0) & "] Where [*数量]>0"
Next
End If
Next Sht
StrSQL = "TransForm Sum([*数量]) Select 商品名称 From (" & Mid(StrSQL, 12) & ") Group By 商品名称 Pivot 日期"
Set Rst = Cn.Execute(StrSQL)
For i = 0 To Rst.Fields.Count - 1
Cells(1, i + 1) = Rst.Fields(i).Name
Next i
Range("A2").CopyFromRecordset Rst
End Sub |
评分
-
2
查看全部评分
-
|