Excelmacros – 如果cell.value有'这个文本'然后

我试图编写代码来find一组文本(如副总裁,总裁,总监等),并将副总裁,执行官或董事分别放在右侧的单元格中。 经过多次尝试,我正在寻求帮助。

Sub Enter_Job_Function() ' ' This Macro is designed to take keywords in the job title column and place ' the approperate Job Function in the approperate column. ' Dim result As String Range("O2").Select Range(Selection, Selection.End(xlDown)).Select ' Cells.Find(What:="Vice President", After:=ActiveCell, LookIn:=xlFormulas _ ' , LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ ' MatchCase:=False, SearchFormat:=False).Activate If InStr(1, ActiveSheet.Range("O2").Value, "Vice President") > 0,_ Then cell.Offset(0, 1).Value "VP" End Sub 

尝试:

 On Error Resume Next Sheet1.Cells.Find("Vice President").Offset(0, 1) = "VP" Sheet1.Cells.Find("President", , , xlWhole).Offset(0, 1) = "Executive" Sheet1.Cells.Find("Director").Offset(0, 1) = "Director" On Error Goto 0 

不确定你的要求,但是这将find你列举的单词的所有第一个实例,并将等效标记放置在它旁边的单元格上。 HTH。