|
- '*********************************
- '******* 北极狐工作室出品 ******
- '******* QQ:14885553 ******
- '*********************************
- Sub Opiona()
- 'On Error Resume Next '// 发生错误,自动执行下一句,就是忽略错误
- Application.ScreenUpdating = False '//关闭屏幕刷新
- Application.DisplayAlerts = False '//关闭系统提示
- t = Timer '//开始时间
- Set SH0 = Sheets("BOM")
- Set SH1 = Sheets("订单表")
- Set SH2 = Sheets("订单需求分析")
- SH2.Range("A2:N65536").ClearContents
- Str_coon = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Excel 12.0;HDR=yes';Data Source =" & ThisWorkbook.FullName '//OFFICE2007
-
- StrSQL = "SELECT A.序列,A.产品图号,A.订单编号,A.单位,A.摘要,A.订单数量2"
- StrSQL = StrSQL & ",B.物料编号,B.物料名称,B.材料,B.规格,B.单位 AS 单位2,B.用量"
- StrSQL = StrSQL & ",B.用量*A.订单数量2 AS 需要用量 FROM ("
-
- StrSQL = StrSQL & "SELECT 序列,产品图号,订单编号,单位,摘要,订单数量2 FROM [" & SH1.Name & "$] WHERE 是否计算='计算' ORDER BY 序列,产品图号,订单编号"
- StrSQL = StrSQL & ") AS A LEFT JOIN ("
-
- StrSQL = StrSQL & "SELECT 产品编号,物料编号,物料名称,材料,规格,单位,用量 FROM [" & SH0.Name & "$] WHERE LEN(产品编号)>0"
- StrSQL = StrSQL & ") AS B ON A.产品图号=B.产品编号"
-
- StrSQL = StrSQL & " ORDER BY A.序列,A.产品图号,A.订单编号"
-
- SQLARR = GET_SQL_To_Arr(StrSQL, Str_coon, False)
- SH2.Range("A2").Resize(UBound(SQLARR, 1) + 1, UBound(SQLARR, 2) + 1) = SQLARR
-
- Application.ScreenUpdating = True '//恢复屏幕刷新
- Application.DisplayAlerts = True '//恢复系统提示
- MsgBox "一共用时:" & Format(Timer - t, "#0.0000") & " 秒", , "北极狐提示!!" '//提示所用时间
- End Sub
复制代码 |
|