|
本帖最后由 zhaogang1960 于 2016-2-19 17:12 编辑
B6模糊查询C列,B7模糊查询B列,那么,在C列中差 33,在B列中差 答复Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(0, 0) <> "B6" And Target.Address(0, 0) <> "B7" Then Exit Sub
If [b6] = "" Or [b7] = "" Then Exit Sub
Dim arr, brr(1 To 100000, 1 To 2), i&, m&, t1$, t2$, sh As Worksheet
t2 = [b6]
t1 = [b7]
With CreateObject("VBSCRIPT.REGEXP")
.Global = True
.Pattern = "(.|$)"
For Each sh In Worksheets
If sh.Name <> "首页" Then
arr = sh.Range("B5:C" & sh.Range("B" & Rows.Count).End(xlUp).Row)
For i = 1 To UBound(arr)
If arr(i, 1) Like .Replace(t1, "*$1") And InStr(arr(i, 2), t2) > 0 Then
m = m + 1
brr(m, 1) = arr(i, 1)
brr(m, 2) = arr(i, 2)
End If
Next
End If
Next
End With
Range("A8:B" & Rows.Count).ClearContents
If m > 0 Then Range("A8").Resize(m, 2) = brr
End Sub
结果当然是什么也没有查到:
跨表模糊查询-包含关键字.rar
(28.95 KB, 下载次数: 72)
|
|