|
- Sub ADO批量评定复习()
- Set cnn = CreateObject("adodb.connection")
- Set rs = CreateObject("adodb.Recordset")
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- For Each sh In Sheets
- If sh.Name <> "名册表" And sh.Name <> "表模" Then
- sh.Delete
- End If
- Next
- Application.DisplayAlerts = True
- cnn.Open "provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data source=" & ThisWorkbook.FullName
- sql = "select distinct 配合比编号 from [名册表$] where 配合比编号 is not null"
- Set rs = cnn.Execute(sql)
- brr = cnn.Execute(sql).getRows
- cnn.Close
- cnn.Open "provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data source=" & ThisWorkbook.FullName
- For x = 0 To UBound(brr, 2)
- Sheets.Add after:=Sheets(Sheets.Count)
- Sheets(2).Rows("1:157").Copy [a1]
- Sheets(2).Columns("A:T").Copy [a1]
- ActiveSheet.Name = brr(0, x)
- sql = "select 抗压强度 from [名册表$] where 配合比编号='" & brr(0, x) & "'"
- Set rs = CreateObject("adodb.Recordset")
- rs.Open sql, cnn, 1, 1
- ActiveSheet.UsedRange.Offset(15).ClearContents
- If rs.RecordCount > 0 Then
- ReDim crr(1 To rs.RecordCount, 1 To 20)
- For i = 1 To rs.RecordCount
- m = Int((i - 1) / 10) + 1
- j = i Mod 10
- If j = 0 Then j = 10
- crr(m, (j - 1) * 2 + 1) = rs.Fields(0).Value
- rs.MoveNext
- Next i
- [a16].Resize(m, 20) = crr
- Else
- MsgBox "没有查到", vbInformation
- End If
- Next x
- Set rs = Nothing
- Set cnn = Nothing
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|