|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub docnn()
Dim cnn As Object, i%, j%, x%, rs As Object, arr, brr
Set cnn = CreateObject("adodb.connection")
cnn.Open "provider=microsoft.ace.oledb.12.0;extended properties=excel 12.0; data source=" & ThisWorkbook.FullName
Sql = "select 料号,sum(数量) as 求和 from [Sheet1$a1:b10] group by 料号"
Set rs = cnn.Execute(Sql)
For i = 0 To rs.fields.Count - 1
Cells(1, i + 7) = rs.fields(i).Name
Next
Range("g2").CopyFromRecordset rs
arr = Range("a1:c10")
brr = Range("g1:h8")
For j = 2 To UBound(arr)
For x = 2 To UBound(brr)
If arr(j, 1) = brr(x, 1) Then
arr(j, 3) = brr(x, 2)
End If
Next
Next
Range("a1").Resize(UBound(arr), 3) = arr
Range(Cells(1, 5), Cells(100, 15)).Clear
rs.Close: Set rs = Nothing
cnn.Close: Set cnn = Nothing
End Sub
|
评分
-
1
查看全部评分
-
|