Excel 如何搜索文本并将值填入宏中的下一个单元格?

Excel 如何搜索文本并将值填入宏中的下一个单元格?,excel,vba,Excel,Vba,我有一个长文本的长数据列表。我想通过查找单词(在A列中)来识别文本,如果匹配,则在下一个单元格中填充值(B列)。我知道我可以通过公式实现,但条件太多了。这会使电子表格的速度变慢。如何用宏实现它?例如: Column A | Column B ---------------- ------------- this is apple | apple this is grape | grape this is banana | banana etc..... 那

我有一个长文本的长数据列表。我想通过查找单词(在A列中)来识别文本,如果匹配,则在下一个单元格中填充值(B列)。我知道我可以通过公式实现,但条件太多了。这会使电子表格的速度变慢。如何用宏实现它?例如:

Column A        |  Column B
---------------- -------------
this is apple   |  apple

this is grape   |  grape

this is banana  |  banana

etc.....

那么您想让宏复制B列中的单词并粘贴到A列中吗?你能解释一下最初的情况是什么,以及你希望宏做什么吗?它不是复制而是搜索文本。例如,如果它包含apple,则写下我在下一个单元格或我定义的单元格中定义的文本。希望这是清楚的。有可能增加更多的条件吗?我有12个词要搜索。
Dim LookFor As String
'This will be a placeholder for the word you want to search for

LookFor = "apple"

On Error Resume Next  
   'in case we could not find the word, we need to continue

Range("A:A").Find(LookFor).Select

If Err = 0 Then
    'if there are no errors, that means we found the word

    Activecell.Offset(0, 1).Value = LookFor
    ' put the same word on the next column, same row
Else
    'there was an error, meaning: the word was not found
    MsgBox "Could not find " & LookFor
End If

'we need to cancel our error detection strategy so that 
' new errors will be reported to the user, otherwise, strange things 
' might happen later
On Error Goto 0