Option Explicit
Sub TEST2()
Dim ar, br, vResult, i&, j&, r&, isFlag As Boolean
Application.ScreenUpdating = False
ar = Worksheets("数据基础表").[A1].CurrentRegion.Value
br = Worksheets("源数据").[A1].CurrentRegion.Value
ReDim vResult(1 To UBound(br), 1 To 4)
For i = 2 To UBound(br) - 1
r = r + 1
vResult(r, 2) = br(i, 1)
vResult(r, 3) = br(i, 13)
vResult(r, 4) = br(i, 14)
isFlag = False
For j = 2 To UBound(ar)
If ar(j, 2) = br(i, 1) Then
vResult(r, 1) = ar(j, 1)
isFlag = True
Exit For
End If
Next j
If isFlag = False Then vResult(r, 1) = "未指定供应商"
Next i
[A1].CurrentRegion.Clear
[A1].Resize(, 4) = Array("供应商", "品名", "合计", "单位")
[A2].Resize(r, UBound(vResult, 2)) = vResult
Application.ScreenUpdating = True
Beep
End Sub
|