返回列表 上一主題 發帖

[發問] 如何刪除字串內指定文字或是保留指定文字?

  1. Sub 刪除C()
  2. Dim Ay()
  3. For Each a In Range("E2:E4")
  4. ar = Split(a, ",")
  5. For Each c In ar
  6.   If Not c Like "C*" Then
  7.     ReDim Preserve Ay(s)
  8.     Ay(s) = c
  9.     s = s + 1
  10.   End If
  11. Next
  12. a.Value = Join(Ay, ",")
  13. Erase Ay: s = 0
  14. Next
  15. End Sub

  16. Sub 保留P()
  17. Dim Ay()
  18. For Each a In Range("E2:E4")
  19. ar = Split(a, ",")
  20. For Each c In ar
  21.   If c Like "P*" Then
  22.     ReDim Preserve Ay(s)
  23.     Ay(s) = c
  24.     s = s + 1
  25.   End If
  26. Next
  27. a.Value = Join(Ay, ",")
  28. Erase Ay: s = 0
  29. Next
  30. End Sub
複製代碼
回復 1# marklos
學海無涯_不恥下問

TOP

回復 3# marklos
  1. Sub 保留P()
  2. Dim Ay()
  3. For Each a In Range("E2:E4")
  4. ar = Split(a, ",")
  5. For Each c In ar
  6.   If c Like "P*" Then
  7.     ReDim Preserve Ay(s)
  8.     Ay(s) = c
  9.     s = s + 1
  10.   End If
  11. Next
  12. a.Value = Join(Ay, ",")
  13. a.Offset(, -1) = s
  14. Erase Ay: s = 0
  15. Next
  16. End Sub
複製代碼
學海無涯_不恥下問

TOP

        靜思自在 : 不要隨心所欲,要隨心教育自己。
返回列表 上一主題