- 帖子
- 472
- 主題
- 5
- 精華
- 0
- 積分
- 485
- 點名
- 0
- 作業系統
- Windows
- 軟體版本
- MS Office
- 閱讀權限
- 100
- 性別
- 男
- 來自
- 香港
- 註冊時間
- 2010-7-4
- 最後登錄
- 2014-12-28

|
2#
發表於 2011-1-26 00:44
| 只看該作者
先找一次aaa,再找一次bbb.
最後的finalrange會顯示 兩個值 都有的cell
取代的話你可以在找出來的range再做手腳
Dim result1 As Range, result2 As Range, finalresult As Range
With Worksheets(1).Range("a1:C500")
Set c = .Find("aaa", LookIn:=xlValues)
firstAddress = c.Address
If Not c Is Nothing Then
Set result1 = c
Do
Set result1 = Union(result1, c)
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
With Worksheets(1).Range("a1:C500")
Set c = .Find("bbb", LookIn:=xlValues)
firstAddress = c.Address
If Not c Is Nothing Then
Set result2 = c
Do
Set result2 = Union(result2, c)
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
Set finalresult = Intersect(result1, result2)
msgbox(finalresult.Address) |
|