|
Sub limonet()
Dim Cn As Object, StrSQL$, Rst As Object, Arr As Variant, Brr As Variant, i%, F$
Set Cn = CreateObject("Adodb.Connection")
Set Rst = CreateObject("Adodb.RecordSet")
Cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & ThisWorkbook.FullName
Brr = Cn.Execute("Select Distinct 客户名称 From [数据源$]").GetRows
F = "Select 商品名称,'农药残留(有机磷及氨基甲酸酯)' As 检测项目,'GB/T 5009.199-2003' As 判定依据,'' as 空,'<50%' As 判定标准,iif(结果 is Null,0,结果) From [数据源$] Where 客户名称='"
For i = 0 To UBound(Brr, 2)
Range("B5:G25") = Null
[C2] = Brr(0, i): StrSQL = F & Brr(0, i) & "'": If Rst.State = 1 Then Rst.Close
Rst.Open StrSQL, Cn, 1, 3
If Rst.RecordCount > 18 Then
Do Until Rst.EOF
Arr = Application.Transpose(Rst.GetRows(18))
Range("B5").Resize(UBound(Arr), 6) = Arr
'ActiveSheet.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
Range("B5:G25") = Null
Loop
Else
Range("B5").CopyFromRecordset Rst
'ActiveSheet.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
End If
Next i
End Sub |
评分
-
1
查看全部评分
-
|