如何从单元格中删除特定文本

How to remove specific text from a cell

例如,在单元格 A1 中我可能有 "Assistant to the Regional Manager." 我最初的想法是像这样使用 Instr:

If InStr(1, Cells(x, 1).Value, "Assistant") > 0 Then
        Cells(x, 1).Value = Cells(x, 1).Value - "Assistant to the "

所以只剩下 "Regional Manager",但这不起作用。有没有办法删除 "Assistant to the "?

怎么样

Cells(x, 1).Value = Replace(Cells(x, 1).Value, "Assistant to the ", "")

有多种方法可以实现你想要的

  1. Replace:FoxInCloud 已经介绍过了。 <==这是最简单的
  2. Split:

    Debug.Print Split(Cells(x, 1).Value,"Assistant to the ")(1)
    
  3. Mid/Len:

    Debug.Print Mid(Cells(x, 1).Value, Len("Assistant to the ") + 1, _
    Len(Cells(x, 1).Value) - Len("Assistant to the "))
    
  4. Right/Len:

    Debug.Print Right(Cells(x, 1).Value, Len("Assistant to the "))
    

我强烈建议您花一些时间研究这些函数的工作原理以获得更好的想法。