|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
请参考
Sub test()
Set d = CreateObject("Scripting.Dictionary")
arr = Sheet2.[a1].CurrentRegion
brr = Sheet1.[a1].CurrentRegion
For i = 3 To UBound(arr)
For j = 3 To UBound(arr, 2) Step 5
s = arr(i, j - 2)
arr(i, j) = WLOOKUP(s, Sheet1.[B:E], , -1)
arr(i, j + 1) = WLOOKUP(s, Sheet1.[B:E], , 2)
arr(i, j + 2) = WLOOKUP(s, Sheet1.[B:E], , 1)
Next
Next
Sheet2.[a1].CurrentRegion = arr
End Sub
Function WLOOKUP(X, M As Variant, Optional a = 1, Optional b = 2)
'比VLOOKUP函数更强大的函数:参数 a 查询第几个;b 返回第几列,可以为负数。
Dim i As Integer
i = Application.CountIf(M, X)
Set M = Intersect(M.Parent.UsedRange, M)
For Each MR In M
If MR.Value = X Then
y = y + 1
If y > i Then Exit Function
If y = a Then
WLOOKUP = MR.Offset(0, b).Value
End If
End If
Next MR
End Function
|
评分
-
1
查看全部评分
-
|