返回列表 上一主題 發帖

Excel 尋找 多筆 "關鍵字"

Excel 尋找 多筆 "關鍵字"

Dear 各位大大,

我想請問 Excel 常用的Ctrl +F 的尋找取代功能。

有沒有辦法同時輸入兩個or以上的"關鍵字"讓 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

回復 2# kimbal


    Dear 大大,
謝謝您,使用上有些問題想請教。
執行巨集會出現錯誤,偵錯在最後一行 "msgbox(finalresult.Address)"

請不吝指教~ 感恩阿~

TOP

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

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

TOP

        靜思自在 : 我們最大的敵人不是別人.可能是自己。
返回列表 上一主題