|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 andanok 于 2013-9-13 21:06 编辑
Sub 更新链接()
Dim iRow
Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim WshShell, BtnCode
Dim SQL As String
con.Open "Provider=SQLOLEDB;Data Source=(local); User ID=sa;Password =123;Database=test;" '打开本地服务器
iRow = [E:E].Find("*", SearchOrder:=xlByRows, LookIn:=xlValues, SearchDirection:=xlPrevious).EntireRow.Row
Dim Dic As Object, i%, j%
Set Dic = CreateObject("Scripting.Dictionary")
SQL = "Select SKU,ProductId from Products" '查询
Arr = Application.Transpose(con.Execute(SQL).GetRows)
Range("C2:D" & iRow) = Arr
Arr = Range("C2:D" & iRow)
For i = 1 To UBound(Arr)
Dic(Arr(i, 1)) = Arr(i, 2)
Next
brr = Range("E2:E" & iRow)
For j = 1 To UBound(brr)
brr(j, 1) = Dic(brr(j, 1))
Next
Range("Z2:Z" & iRow) = brr
con.Close
Set con = Nothing
End Sub
其实只要VLOOKUP效果,数据量大的远程更新到EXCEL
Z2=VLOOKUP(E2,【SQL中表Products的SKU,ProductId】,0)
Z3=VLOOKUP(E3,……
……
现在只现实SQL到C、D列,再进行字典找对应的,能否不用过度的C、D列,更简单点呢,毕竟数据量大,多一步就会影响速度了,谢谢各位了
|
|
|
|
|