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

时间:2015-09-15 20:00:58

标签: excel excel-vba excel-2013 vba

例如,在单元格A1中,我可能有“区域经理助理”。我最初的想法就是像这样使用Instr:

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

所以只剩下“区域经理”,但这不起作用。有没有办法删除“助理”?

2 个答案:

答案 0 :(得分:3)

怎么样?
Cells(x, 1).Value = Replace(Cells(x, 1).Value, "Assistant to the ", "")

答案 1 :(得分:1)

有多种方法可以达到你想要的效果

  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 "))
    
  5. 我强烈建议您花一些时间研究这些功能如何运作以获得更好的想法。

相关问题