|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 查询()
Dim cnn As Object
Dim Sql As String, r%
Set cnn = CreateObject("ADODB.CONNECTION")
r = [g13].End(3).Row
If r = 4 Then Exit Sub
cnn.Open "Provider=Microsoft.ACE.OleDb.12.0;Extended Properties='Excel 12.0;HDR=YES'; Data Source=" & ThisWorkbook.FullName
Sql = "select 料号,品名,规格,单位 from [sheet1$g4:g" & r & "] a left join [sheet2$a1:e] b on a.批号=b.批号"
[a5:d12] = ""
[a5].CopyFromRecordset cnn.Execute(Sql)
cnn.Close: Set cnn = Nothing
End Sub
这个用字典更简单一些。 |
|