|
全匹配的在前,部分匹配的在后面:- Sub Find法()
- Dim c As Range, firstAddress$, arr(), brr(), m&, n&, temp$
- temp = [c1]
- ReDim arr(1 To [a65536].End(xlUp).Row, 1 To 1)
- ReDim brr(1 To [a65536].End(xlUp).Row, 1 To 1)
- With Range("a:a")
- Set c = .Find(temp, , , 2)
- If Not c Is Nothing Then
- firstAddress = c.Address
- Do
- If c.Value = temp Then
- m = m + 1
- arr(m, 1) = c.Offset(, 1)
- Else
- n = n + 1
- brr(n, 1) = c.Offset(, 1)
- End If
- Set c = .FindNext(c)
- Loop While Not c Is Nothing And c.Address <> firstAddress
- End If
- End With
- Range("d2:d65536").ClearContents
- If m > 0 Then [d2].Resize(m) = arr
- If n > 0 Then [d65536].End(xlUp).Offset(1).Resize(n) = brr
- End Sub
复制代码 |
|