我有一個數字,我需要在Excel自動分類敘述描述:VBA:多個關鍵字VLOOKUP
Description Category
I updated the o.s.
I installed the o.s.
I cleaned valve a
I cleaned valve b
I installed valve a
Today the o.s. was updated
我有一個關鍵字,另一個工作表和關鍵字關聯的類別:
Keyword 1 Keyword 2 Keyword 3 Category
cleaned valve a A
installed valve a B
updated os C
installed os D
到目前爲止我的代碼只能在一個時間搜索一個關鍵字,所以因爲一些關鍵字在多個敘事用於將報告不正確的答案:
Public Function Test21(nar As Range, ky As Range) As String
Dim sTmp As String, vWrd As Variant, vWrds As Variant
'Splits Fsr Narrative into individual words so it can be searched for keywords'
vWrds = Split(nar)
For Each vWrd In vWrds
If Not IsError(Application.VLookup(vWrd, ky, 3, False)) Then
sTmp = Application.VLookup(vWrd, ky, 3, False)
Exit For
End If
Next vWrd
Test21 = sTmp
End Function
我見過像this這樣的算法,但我覺得我的目標可以更簡單地完成,因爲所有的敘述都比較簡單。
感謝您的閱讀!
'vWrds =斯普利特(NAR)'你需要'split'的分隔符。 – findwindow
更具體地說,根據你的例子,你需要用'(空格)'...'vWrds = Split(nar,「」)來劃分'nar'' –