我有一个数字,我需要在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'' –