VBA – 快速search关键字的方法

我正在执行关键字search(循环访问Excel列,查找包含在另一个电子表格中的关键字,并将值分配给第一个电子表格中的另一列(如果find的话))。 我正在通过使用for循环和if – else语句来做到这一点,而且它certificate是相当慢的 。 关键字工作表有三列可input关键字,一列用于指定值。 这个想法是,如果要分配的值,被扫描的文本应该包含在这些关键字列中input的所有关键字。 在关键字之前加一个“ – ”表示如果扫描的文本不包含指定的关键字,则只能分配该值。 有关使用的方法,请参阅下面的代码。 我的问题的重点在它的效率。

Dim intLoopKeywordsRows As Integer Dim intLoopDataShortTextRows As Integer Dim strDataShortText As String Dim strKeyword_A As String Dim strKeyword_B As String Dim strKeyword_C As String Dim strCheck_B As String Dim strCheck_C As String Dim lastRow Dim i As Integer lastRow = Data.Cells(Rows.Count, 1).End(xlUp).Row For intLoopKeywordsRows = 2 To lastRow For intLoopDataShortTextRows = 2 To lastRow '================================================================================== '================================================================================== If Data.Range("S" & intLoopDataShortTextRows) = "" Then '===========only if column S is blank strDataShortText = Trim(UCase(Data.Range("G" & intLoopDataShortTextRows))) strKeyword_A = UCase(wsKeywords.Range("A" & intLoopKeywordsRows)) strCheck_B = "" If Left(wsKeywords.Range("B" & intLoopKeywordsRows), 1) = "-" Then strCheck_B = "Neg" strKeyword_B = UCase(Right(wsKeywords.Range("B" & intLoopKeywordsRows), Len(wsKeywords.Range("B" & intLoopKeywordsRows)) - 1)) ElseIf wsKeywords.Range("B" & intLoopKeywordsRows) <> "" Then strCheck_B = "Pos" strKeyword_B = UCase(wsKeywords.Range("B" & intLoopKeywordsRows)) End If strCheck_C = "" If Left(wsKeywords.Range("C" & intLoopKeywordsRows), 1) = "-" Then strCheck_C = "Neg" strKeyword_C = UCase(Right(wsKeywords.Range("C" & intLoopKeywordsRows), Len(wsKeywords.Range("C" & intLoopKeywordsRows)) - 1)) ElseIf wsKeywords.Range("C" & intLoopKeywordsRows) <> "" Then strCheck_C = "Pos" strKeyword_C = UCase(wsKeywords.Range("C" & intLoopKeywordsRows)) End If Dim Check_JumpLoop As Integer Check_JumpLoop = 0 '================if negative values found then go to next Data Text====================== If (strCheck_B = "Neg" And InStr(strDataShortText, strKeyword_B) > 0) Or (strCheck_C = "Neg" And InStr(strDataShortText, strKeyword_C) > 0) Then Check_JumpLoop = 1 End If '######################################################################################## '======================================================================================== If Check_JumpLoop = 0 Then If strCheck_B = "Pos" And strCheck_C = "Pos" Then If InStr(strDataShortText, strKeyword_A) > 0 And InStr(strDataShortText, strKeyword_B) > 0 And InStr(strDataShortText, strKeyword_C) > 0 Then Data.Range("S" & intLoopDataShortTextRows) = wsKeywords.Range("E" & intLoopKeywordsRows) End If ElseIf strCheck_B = "Pos" And strCheck_C <> "Pos" Then If InStr(strDataShortText, strKeyword_A) > 0 And InStr(strDataShortText, strKeyword_B) > 0 Then Data.Range("S" & intLoopDataShortTextRows) = wsKeywords.Range("E" & intLoopKeywordsRows) End If ElseIf strCheck_B <> "Pos" And strCheck_C = "Pos" Then If InStr(strDataShortText, strKeyword_A) > 0 And InStr(strDataShortText, strKeyword_C) > 0 Then Data.Range("S" & intLoopDataShortTextRows) = wsKeywords.Range("E" & intLoopKeywordsRows) End If ElseIf strCheck_B <> "Pos" And strCheck_C <> "Pos" Then If InStr(strDataShortText, strKeyword_A) > 0 Then Data.Range("S" & intLoopDataShortTextRows) = wsKeywords.Range("E" & intLoopKeywordsRows) End If End If End If '######################################################################################## End If '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ Next intLoopDataShortTextRows Next intLoopKeywordsRows 

我的问题是,是否有一个更快/更有效的方式来做到这一点?

编辑:数据描述

数据栏包含说明,如“绿色花园软pipe”。

关键字表单包含三列用于input关键字的列。 这些是单词如“HOSE”,“GREEN”和“GARDEN”。 要将关键字与值(在本例中为数字)进行匹配,它必须匹配三列中的所有关键字,但不需要填充列。 如果只有一个关键字,则只会查找该关键字。 如果在两列中有两个关键字,说明必须包含两个等

在关键字之前放置“ – ”表示现在必须将关键字排除在要分配的值之外。 EG表示描述为“蓝色面板”,前两个关键字列包含“PANEL”和“-BLUE”,由于BLUE必须从描述中排除,因此不会赋值。