在VBA中search范围并replace包含特定string的单元格的内容
我试图通过Excel电子表格中包含string的单元格范围。 如果一个特定的单元格包含特定的string,我想用同一个stringreplace整个单元格。 我打出了我认为应该工作的东西,但我什么都没有得到。 任何帮助,将不胜感激!
Sub Supportclean() Dim c As Range Dim celltext As String For Each c In Range("E:E") If InStr(1, celltext, "horse") > 0 Then Range(c) = "horse" End If Next c End Sub
非常感谢!
你可以一次做整个列,不需要循环:
Sub supportclean() Range("E:E").Replace "*horse*", "horse" End Sub
用你的循环replace
For Each c In Range("E:E") If InStr(1, c.Text, "horse") > 0 Then c.Formula = "horse" End If Next c
在For Each c In Range(“E:E”)后添加此代码
celltext = c.value
希望这个帮助。