|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
感覺運用dic跟vlookup方法很像
若直接使用vba運用vlookup去找關鍵值 也是一種方法吧!
若不熟vba者,可以增加輔助欄(結合3關鍵字),不用vba直接在工作表用vlookup 函數去求得解答!
Sub test2()
Dim Brr()
[F1].CurrentRegion.Columns(5).Offset(1).ClearContents
arr = [A1].CurrentRegion
r = UBound(arr) - 1
ReDim Brr(1 To 2, 1 To r)
'-----------------------------
For i = 2 To UBound(arr)
m = m + 1
Brr(1, m) = arr(i, 1) & "|" & arr(i, 2) & "|" & arr(i, 3)
Brr(2, m) = arr(i, 4)
Next
'-----------------------------
Brr = Application.Transpose(Brr)
Set A = Range([F2], [F2].End(4))
For i = 1 To A.Cells.Count
With A.Cells(i)
On Error Resume Next 'if Not Found Error Happen Continue anyway!
x = .Offset(, 1) & "|" & .Offset(, 2) & "|" & .Offset(, 3)
.Offset(, 4) = Round(Application.VLookup(x, Brr, 2, 0), 2)
If Err.Number <> 0 Then .Offset(, 4) = "No Found!"
On Error GoTo 0 'Reset Err=0
End With
Next
'-----------------------------
End Sub |
|