![](/img/trans.png)
[英]VBA Error Handling: Unable to get the match property of the worksheet function class
[英]VBA: Unable to get the Match property of the WorkSheet function class
有人可以建議以下代碼。 我希望能夠找到出現“索引”的列:
Sub Test()
Dim d As Range
Dim a As Variant
Set d = Sheet2.Range("H349:M349")
a = Application.WorksheetFunction.Match("Index", d, 0)
End Sub
但是我在最后一行說了一個錯誤:
無法獲取WorkSheet函數類的Match屬性
您確定單詞“索引”(並且只有“索引”)本身出現在Sheet2的一個單元格中(可能不必與Sheets(“ Sheet2”)相同)是H349:M349嗎?
在VBA中,匹配可能很容易出錯,因此我更喜歡使用Range.Find方法,該方法可以進行Nothing測試(找不到):
Sub Test()
Dim rngFound As Range
Set rngFound = Sheet2.Range("H349:M349").Find("Index", , xlValues, xlWhole)
If Not rngFound Is Nothing Then
'Found a match
MsgBox "Found a match at " & rngFound.Address
Else
'No matches
MsgBox "No matches"
End If
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.