|
Sub 查询()
Dim cnn As Object
Dim Sql As String, sh As Worksheet
Set cnn = CreateObject("ADODB.CONNECTION")
cnn.Open "Provider=Microsoft.ACE.OleDb.12.0;Extended Properties='Excel 12.0;HDR=YES'; Data Source=" & ThisWorkbook.FullName
Sql = "select distinct * from [sheet1$a1:g] where 支数 is not null"
Sql = "select 单据号码,产品型号,货品型号,子件描述,sum(订单数量),仓库,sum(支数) from (" & Sql & ")" _
& " group by 单据号码,产品型号,货品型号,子件描述,仓库"
Application.DisplayAlerts = False
For Each sh In Sheets
If sh.Name <> "Sheet1" Then
sh.Delete
End If
Next
Sheets.Add after:=Sheets(1)
Application.DisplayAlerts = True
Sheet1.[a1:g1].Copy [a1]
[a2].CopyFromRecordset cnn.Execute(Sql)
cnn.Close: Set cnn = Nothing
End Sub
返回结果
单据号码 | 产品型号 | 货品型号 | 子件描述 | 订单数量 | 仓库 | 支数 | MLD-180330-003 | TF9139D-8 | B52904100279 | 套管D28*60*T0.8/镀韩国金 | 80 | [52] 电镀仓 | 3 | MLD-180330-003 | TF9139D-8 | B52934103823 | 铝车件美的/D27*H16/中M10内牙/韩国金 | 3 | [52] 电镀仓 | 3 | MLD-180330-003 | TF9139D-8 | B52934103930 | 压铸战鼓铝件D45*30*H20/中孔12.5/镀韩国金 | 30 | [52] 电镀仓 | 5 | MLD-180330-003 | TF9139D-8 | B52934106563 | 锁扣6厘/29*59/韩国金 | 6 | [52] 电镀仓 | 6 | MLD-180330-003 | TF9139D-8 | B52934110979 | 酒杯盖D32*10/中孔10.5/韩国金 | 31 | [52] 电镀仓 | 12 | MLD-180405-003 | TF9139D-8 | B52904100279 | 套管D28*60*T0.8/镀韩国金 | 80 | [52] 电镀仓 | 3 | MLD-180606-001 | TF5211D-6 | B52934128589 | TF5211铝车件D37*10/中孔16.5/上下凹卡口D32*1/韩国金 | 1000 | [52] 电镀仓 | 10 |
|
|