还是有以下报错!不知道什么原因?
- Sub MonthFind()
- Dim cnn As Object, Sql As String, yf, i&
- Set cnn = CreateObject("adodb.connection")
- cnn.Open "provider=microsoft.jet.oledb.4.0;extended properties='excel 8.0;hdr=yes;imex=1';data source=" & ThisWorkbook.FullName
- yf = "# " & Sheet3.[j4] & " #"
- With Sheet3
- .[a6:i65536].ClearContents
- Sql = "select [件号],[名称],[计划价],sum(数量) as d,sum(金额) as e,0 as f,0 as g,0 as h ,0 as i from [入库登记$a5:l65536] where 入库日期 < & yf & group by 件号,名称,计划价 union all " _
- & "select [件号],[名称],[计划价],-sum(数量) as d,-sum(金额) as e,0 as f,0 as g,0 as h ,0 as i from [出库登记$a5:n65536] where 出库日期 < & yf & group by 件号,名称,计划价 union all " _
- & "select [件号],[名称],[计划价],0 as d,0 as e,sum(数量) as f,sum(金额) as g,0 as h,0 as i from [入库登记$a5:l65536] where 入库日期 = & yf & group by 件号,名称,计划价 union all " _
- & "select [件号],[名称],[计划价],0 as d,0 as e,0 as f ,0 as g,sum(数量) as h ,sum(金额) as i from [出库登记$a5:n65536] where 出库日期 = & yf & group by 件号,名称,计划价"
- Sql = "select [件号],[名称],[计划价],sum(d),sum(e),sum(f),sum(g),sum(h),sum(i) from (" & Sql & ") where [件号] is not null group by 件号,名称,计划价"
- .[a6].CopyFromRecordset cnn.Execute(Sql)
- For i = 6 To .[a65536].End(xlUp).Row
- .Cells(i, "j") = .Cells(i, "d") + .Cells(i, "f") - .Cells(i, "h")
- .Cells(i, "k") = .Cells(i, "e") + .Cells(i, "g") - .Cells(i, "i")
- Next
- End With
- End Sub
复制代码 |