检查单元格是否包含特定文本

时间:2015-05-22 17:01:28

标签: excel vba excel-vba

我必须按照优先顺序将作业从一个电子表格放到另一个电子表格中。如果作业被列为已完成,那么我不会转移该作业。以下是我的最高优先级代码,"优先级1"。声明它完成状态的单元格有时会在它之前或之后有一个日期,这就是为什么我把它放在" *"字符。

Do Until IsEmpty(ActiveCell) Or count > 14
                If ActiveCell.Value = "Priority I" Then
                    ActiveCell.Offset(0, 6).Select
                    If ActiveCell.value = "completed" like "*completed*" Then
                    ActiveCell.Offset(1, -6).Select
                    Else
                    ActiveCell.Offset(0, -1).Select
                    word0 = ActiveCell.Value
                    ActiveWindow.ActivateNext
                    ActiveCell = word0
                    ActiveWindow.ActivateNext
                    ActiveCell.Offset(0, -9).Select
                    word = Left(ActiveCell.Value, 6)
                    ThisWorkbook.Activate
                    ActiveCell.Offset(0, 1).Select
                    ActiveCell = word
                    ActiveWindow.ActivateNext
                    ActiveCell.Offset(0, 1).Select
                    word1 = ActiveCell.Value
                    ThisWorkbook.Activate
                    ActiveCell.Offset(0, 1).Select
                    ActiveCell.Value = word1
                    ActiveWindow.ActivateNext
                    ActiveCell.Offset(0, 1).Select
                    word2 = ActiveCell.Value
                    ThisWorkbook.Activate
                    ActiveCell.Offset(0, 1).Select
                    ActiveCell.Value = word2
                    ActiveWindow.ActivateNext
                    ActiveCell.Offset(0, 1).Select
                    word3 = ActiveCell.Value
                    ThisWorkbook.Activate
                    ActiveCell.Offset(0, 1).Select
                    ActiveCell.Value = word3
                    ActiveCell.Offset(1, -4).Select
                    ActiveWindow.ActivateNext
                    ActiveCell.Offset(1, 1).Select
                    count = count + 1
                    End If
                    Else
                    ActiveCell.Offset(1, 0).Select
               End If
            Loop

我已经确认它正在检查正确的列,它只是没有抓住完成的单词。所以问题在于第4行。

1 个答案:

答案 0 :(得分:2)

更改

 If ActiveCell.value = "completed" like "*completed*" Then

If Instr(1, UCase(ActiveCell.Value), "COMPLETED") > 0 Then

If UCase(ActiveCell.Value) like "*COMPLETED*" Then