|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 按钮1_Click()
Dim dic, arr()
Set dic = CreateObject("Scripting.Dictionary")
Set cnn = CreateObject("adodb.connection")
cnn.Open "provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data source=" & ThisWorkbook.FullName
Sql2 = "select * from [sheet2$]"
Set rst2 = CreateObject("adodb.Recordset")
rst2.Open Sql2, cnn, 1, 1
k = 0
ReDim arr(1 To rst2.RecordCount, 1 To 5)
Do While Not rst2.EOF
k = k + 1
dic(rst2("号码") & "") = k
arr(k, 1) = rst2("属性1")
arr(k, 2) = rst2("属性2")
arr(k, 3) = rst2("单价")
arr(k, 4) = rst2("属性2")
arr(k, 5) = rst2("单位")
rst2.movenext
Loop
cnn.Close
Set cnn = Nothing
Dim brr, k0
k0 = [a1].End(4).Row - 1
brr = [a2].Resize(k0, 8)
For i = 1 To k0
k = dic(brr(i, 1) & "")
brr(i, 4) = arr(k, 1)
brr(i, 5) = arr(k, 2)
brr(i, 6) = arr(k, 3)
brr(i, 7) = arr(k, 4)
brr(i, 8) = arr(k, 5)
Next
[a2].Resize(k0, 8) = brr
End Sub
例子2.zip
(16.81 KB, 下载次数: 18)
|
评分
-
2
查看全部评分
-
|