|
Sub test()
Dim st$, ar, br(), k&, r&, c%, i%, b%, t()
st = Replace(Sheet2.[a2], " ", "")
If Len(st) = 0 Then Exit Sub '在这里加个判断不就行了?
For i = 1 To Len(st)
ReDim Preserve t(1 To i)
t(i) = Mid(st, i, 1)
Next
k = 1
ar = Sheet1.[a1].CurrentRegion.Resize(, 4)
ReDim Preserve br(1 To 4, 1 To k)
For i = 1 To 4
br(i, k) = ar(1, i)
Next
For r = 2 To UBound(ar)
b = 1
st = ar(r, 3)
For i = 1 To UBound(t)
b = b * InStr(st, t(i))
Next
If b Then
k = k + 1
ReDim Preserve br(1 To 4, 1 To k)
For c = 1 To UBound(ar, 2)
br(c, k) = ar(r, c)
Next
End If
Next
If k - 1 Then
With Sheet2
.[a3].Resize(.Rows.Count - 2, 4) = ""
.[a3].Resize(k, UBound(br)) = Application.WorksheetFunction.Transpose(br)
End With
End If
End Sub |
|