'可能是这样,猜了2种可能
Option Explicit
Sub test1()
Dim i, arr, s, n, j
arr = Range("b1:c" & Cells(Rows.Count, "b").End(xlUp).Row)
ReDim brr(1 To UBound(arr, 1) * 2, 1 To 1)
s = [a2].Value
For i = 1 To UBound(arr, 1)
For j = 1 To UBound(arr, 2)
If InStr(arr(i, j), s) Then
n = n + 1
brr(n, 1) = arr(i, j)
End If
Next
Next
With [e1]
.Resize(Rows.Count, 2).ClearContents
If n > 0 Then .Resize(n) = brr
End With
End Sub
Sub test2()
Dim i, arr, s, n, j, k
arr = Range("b1:c" & Cells(Rows.Count, "b").End(xlUp).Row)
s = [a2].Value
For i = 1 To UBound(arr, 1)
For j = 1 To UBound(arr, 2)
If InStr(arr(i, j), s) Then
n = n + 1
For k = 1 To UBound(arr, 2)
arr(n, k) = arr(i, k)
Next
Exit For
End If
Next
Next
With [e:f]
.ClearContents
If n > 0 Then .Resize(n, UBound(arr, 2)) = arr
End With
End Sub |