|
本帖最后由 gbgbxgb 于 2018-8-25 19:28 编辑
- Sub theSearchWord()
- Dim arr As Variant, brr As Variant, crr As Variant
- Dim reg As Object, theStr$, thePattern$, i&, j&, theFinalRow&
- '
- With Sheet1
- theFinalRow = .Cells(.Rows.Count, 1).End(xlUp).Row
- If theFinalRow = 1 Then GoTo The_Exit
- With .Range(.Cells(1, 1), .Cells(theFinalRow, 1))
- arr = .Value
- .Offset(1, 1).ClearContents
- End With
- ReDim crr(1 To UBound(arr) - 1, 1 To 1)
- theFinalRow = .Cells(.Rows.Count, 3).End(xlUp).Row
- If theFinalRow = 1 Then GoTo The_Exit
- brr = .Range(.Cells(1, 3), .Cells(theFinalRow, 3))
- '
- Set reg = CreateObject("VBScript.RegExp")
- With reg
- .Global = True
- .ignorecase = True
- For i = 2 To UBound(arr)
- theStr = arr(i, 1)
- For j = 2 To UBound(brr)
- thePattern = "(^|\b)" & brr(j, 1) & "(\b|$)"
- .Pattern = thePattern
- If .Test(theStr) Then
- crr(i - 1, 1) = "是"
- Exit For
- End If
- Next j
- Next i
- End With
- .Cells(2, 2).Resize(UBound(arr) - 1) = crr
- End With
- The_Exit:
- Set reg = Nothing
- End Sub
复制代码
|
|