|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
郁孤亭 发表于 2012-7-31 19:00
如附件,用find法
c1=ax,则结果前面有几个空单元格
c1=AX,则没有
countif不能区分大小写,下面代码区别大小写、使用双数组:- 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, , , True)
- 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
复制代码 |
|