与Excel的VBA – “如果一个单元格包含”thisString“附加”这个文本“到结束一个调用在列F”

下午好,

使用VBA已经很长时间了,有人能够帮助一个macros来search一个相当大的excel表单,它会在一列(A)内寻找特定的触发词,如果发现它会附加“someText”进入同一行F列的单元格?

任何帮助将不胜感激。

此代码findA列中的关键字的所有发生,并写入每个列的F列中的文本。

 Sub test2() Dim ws1 As Worksheet Dim Lastrow As Long Dim ValueToFind As String, TextToInput As String Dim c Set ws1 = ThisWorkbook.Sheets("Sheet1") 'Change the name of your sheet ValueToFind = InputBox("Enter the value that you are looking") With ws1.Columns("A:A") Set c = .Find(ValueToFind, LookIn:=xlValues) If Not c Is Nothing Then TextToInput = InputBox("Enter the text") firstAddress = c.Address Do .Cells(c.Row, "F") = TextToInput Set c = .FindNext(c) Loop While Not c Is Nothing And c.Address <> firstAddress End If End With End Sub 

像这样的东西应该工作:

 Sub AddStringIf() Dim columnA As Range Dim triggerArray Dim IsInArray As Boolean Dim stringToAdd stringToAdd = "Something" triggerArray = Array("TriggerWord1", "TriggerWord2", "TriggerWord3") Set columnA = Range("A1:A100") For Each cell In columnA IsInArray = Not IsError(Application.Match(cell.Value, triggerArray, 0)) If IsInArray Then cell.Offset(, 5) = cell.Value & stringToAdd End If Next cell End Sub