首页 文章

VBA Excel根据一个单元格的内容更改另一个单元格的内容

提问于
浏览
0

你能帮帮我吗? Excel看起来像这样:

Excel Workbook

我希望自动完成两项任务:

  • 当C列中的单元格包含单词"processed" =>清除A列中相应单元格中的内容时

  • 当C列中的单元格包含单词"blue" =>时,将B列中的相应单元格更改为0

我尝试过Offset,循环和其他各种方法,但似乎无法做到正确 . 请帮忙 .

2 回答

  • 0

    使用 InStr -Function检查它是否包含子字符串 . 如需更多信息,请查看here .

  • 0
    Sub removeprocessed()
    Dim Nlines As Long
    Dim i As Long
    Nlines = Columns(1).Find("*", , , , xlByColumns, xlPrevious).Row
    For i = 2 To Nlines
        If 0 <> InStr(1, Cells(i, 3).Value, "processed") Then
            Cells(i, 1).Value = ""
        End If
        If 0 <> InStr(1, Cells(i, 3).Value, "blue") Then
            Cells(i, 2).Value = 0
        End If
    Next
    End Sub
    

    使用@UGP提出的InStr

相关问题