|
- Sub lqxs()
- Dim conn, Sql$, Arr, i&, d, Arr1
- Set d = CreateObject("Scripting.Dictionary")
- On Error GoTo 100
- Set conn = CreateObject("adodb.connection")
- conn.Open "provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Excel 12.0';data source=" & ThisWorkbook.Path & "\表2.xlsx"
- Sql = "select * from [Sheet1$]"
- Sheet1.Activate
- Arr = conn.Execute(Sql).getrows
- For i = 0 To UBound(Arr, 2)
- d(Arr(0, i)) = Arr(1, i)
- Next
- Arr1 = [g1].CurrentRegion
- For i = 2 To UBound(Arr1)
- If d.exists(Arr1(i, 1)) Then
- Cells(i, 4) = d(Arr1(i, 1))
- End If
- Next
- GoTo 200
- 100:
- MsgBox "没有此数据!"
- 200:
- [a2].Select
- conn.Close
- Set conn = Nothing
- End Sub
复制代码 |
|