excel vba find 完全符合 搜尋關鍵字

Step 1 在功能列「開發人員」中程式碼選擇「Visual Basic」

Step 2 複製下方程式碼貼上,並修改尋找的值以及尋找範圍後,按下執行
Sub FindValue()
Dim rng As Range
Dim searchValue As String
Dim foundCell As Range
' 要尋找的值
searchValue = "test"
' 在A欄及B欄中尋找
Set rng = Range("A:B")
' 使用 Find 方法尋找值
Set foundCell = rng.Find(What:=searchValue, LookIn:=xlValues, LookAt:=xlWhole)
' 如果找到,則顯示其地址
If Not foundCell Is Nothing Then
MsgBox "找到值 " & searchValue & " 在儲存格 " & foundCell.Address
Else
MsgBox "找不到值 " & searchValue
End If
End SubRange.Find(What, After, LookIn, LookAt, SearchOrder, SearchDirection, MatchCase, MatchByte, SearchFormat)What: 要尋找的值或條件。After: 從哪個儲存格開始尋找。若省略,則從範圍的第一個儲存格開始。LookIn: 尋找的內容,可以是xlValues(僅尋找儲存格的值)、xlFormulas(僅尋找儲存格的公式)、xlComments(僅尋找儲存格的註解)或xlComments(尋找儲存格的值、公式和註解)。LookAt: 尋找的方式,可以是xlWhole(僅尋找完全匹配的值)或xlPart(尋找部分匹配的值)。SearchOrder: 尋找的順序,可以是xlByRows(按行)或xlByColumns(按列)。SearchDirection: 尋找的方向,可以是xlNext(往前)或xlPrevious(往後)。MatchCase: 填入True或False,是否區分大小寫。MatchByte: 填入True或False,是否區分單位。SearchFormat: 填入True或False,是否尋找儲存格的格式。

Step 3 即可回傳關鍵字值的位置
【教學】Excel VBA 如何使用Find查找值並回傳位置?超簡單馬上搞定!
