|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 模糊查询()
Dim ar As Variant, br As Variant
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("库")
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 2 Then MsgBox "库为空!": End
ar = .Range("a1:f" & r)
End With
With Sheets("sheet1")
rs = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 2 Then MsgBox "查询表为空!": End
.Range("c2:e" & rs) = Empty
br = .Range("a1:e" & rs)
For i = 2 To UBound(br)
d.RemoveAll
If Trim(ar(i, 1)) <> "" And Trim(ar(i, 2)) <> "" Then
rr = Split(br(i, 2), ",")
For s = 0 To UBound(rr)
If rr(s) <> "" Then
d(rr(s)) = ""
End If
Next s
sl = UBound(rr) + 1
For s = 2 To UBound(ar)
gs = 0: m = 0
If InStr(ar(s, 2), br(i, 1)) > 0 Then
rr_1 = Split(ar(s, 4), ",")
For ss = 0 To UBound(rr_1)
If rr_1(ss) <> "" Then
If d.exists(rr_1(ss)) Then
gs = gs + 1
End If
End If
Next ss
If gs = sl Then m = m + 1: xh = s: Exit For
End If
Next s
If m > 0 Then
br(i, 3) = ar(xh, 5)
br(i, 4) = ar(xh, 3)
br(i, 5) = ar(xh, 6)
Else
br(i, 3) = "无"
End If
End If
Next i
.Range("a1:e" & rs) = br
End With
MsgBox "ok!"
End Sub
|
|