Excel宏 - 如果cell.value具有'此文本'然后

时间:2015-02-17 08:51:23

标签: excel vba

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

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

1 个答案:

答案 0 :(得分:0)

尝试:

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

不确定您的要求,但这会找到您枚举的单词的所有第一个实例,并将等效标记放在旁边的单元格上。 HTH。