返回列表 上一主題 發帖

Excel 尋找 多筆 "關鍵字"

先找一次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)
懂得發問,答案就會在其中

今日の一秒は  明日にない
http://kimbalko-chi.blogspot.com
http://kimbalko.blogspot.com

TOP

是找不到的意思, 可以多加一個IF跳過:
IF not finalresult is nothing then
msgbox(finalresult.Address)
end if
懂得發問,答案就會在其中

今日の一秒は  明日にない
http://kimbalko-chi.blogspot.com
http://kimbalko.blogspot.com

TOP

        靜思自在 : 能付出愛心就是福,能消除煩惱就是慧。
返回列表 上一主題