简体   繁体   English

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

[英]VBA Excel Change Content of another Cell based on content of one cell

Can you help me with this. 你能帮我吗 The Excel looks something like this: Excel看起来像这样:

Excel工作簿

I hope to automate 2 tasks: 我希望自动化2个任务:

  1. When cells in Column C contains word "processed" => clear content in corresponding cell in column A 当C列中的单元格包含单词“已处理” =>清除A列中相应单元格中的内容
  2. When cells in Column C contains word "blue" => change corresponding cell in column B to 0 当C列中的单元格包含单词“ blue” =>时,将B列中的相应单元格更改为0

I have tried Offset, Looping and other various method but can't seem to get it right. 我尝试了偏移,循环和其他各种方法,但似乎无法正确处理。 Please help. 请帮忙。

Use InStr -Function to check if it contains the substring. 使用InStr -Function检查它是否包含子字符串。 For Further Informations look here . 有关更多信息,请参见此处

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

Using InStr as proposed by @UGP 使用@UGP建议的InStr

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM