请测试:
Sub testGetValue()
Dim p As String, f As String, s As String, a As String, m As Long, j As Integer
Dim arr, brr(1 To 65535, 1 To 7), d As Object, i As Long, lr As Long, temp
lr = [a65536].End(3).Row
arr = Range("a3:g" & lr).Value
p = ThisWorkbook.Path & "\"
f = "备案汇总表1.xls"
s = "Sheet2"
Set d = CreateObject("scripting.dictionary")
For i = 2 To 65536
a = "B" & i: temp = getvalue(p, f, s, a)
If temp = 0 Then
Exit For
End If
d(temp) = i
Next i
For i = 1 To lr - 2
temp = arr(i, 1)
If d.exists(temp) Then
a = "F" & d(temp): arr(i, 3) = getvalue(p, f, s, a)
a = "H" & d(temp): arr(i, 5) = getvalue(p, f, s, a)
a = "K" & d(temp): arr(i, 6) = getvalue(p, f, s, a)
a = "I" & d(temp): arr(i, 7) = getvalue(p, f, s, a)
End If
Next i
Range("a3:g" & lr).Value = arr
MsgBox "处理完毕"
End Sub
Private Function getvalue(pa As String, File As String, SHEET As String, REF As String)
Dim arg As String
arg = "'" & pa & "[" & File & "]" & SHEET & "'!" & Range(REF).Range("A1").Address(, , xlR1C1)
getvalue = ExecuteExcel4Macro(arg)
End Function
[ 本帖最后由 zhaogang1960 于 2008-12-9 18:58 编辑 ] |