我试了一下好象不行
Sub SeachData() 'sql查询实例 Dim x As Object, mydate As Variant mydate = Range("j2").Value Set x = CreateObject("ADODB.Connection") x.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;HDR=YES;';Data Source=" & ThisWorkbook.FullName For i = 5 To Range("a65536").End(xlUp).Row Sql = "select Sum(数量) from [明细$] where 品号='" & Sheets("品种表").Cells(i, 1).Value & "'and 日期<=#" & mydate & "#" Next i
Set y = x.Execute(Sql) Sheets("品种表").Range("L2").CopyFromRecordset y x.Close Set y = Nothing End Sub
我用这样的代码可以么?
想在 Sql = "select Sum(数量) from [明细$] where 品号='" & Sheets("品种表").Cells(i, 1).Value & "'and 日期<=#" & mydate & "#" 这句上做文章不知道可以不可以!? |