Excel-VBA:如果最后3个字符相等(则不影响单元格的格式),请删除它们。

问题描述 投票:1回答:1

我已经发布了一个类似的问题,但是很遗憾,我意识到我无法使用任何解决方案,因为所有解决方案都删除了单元格中的所有格式:(

我有一个替换各种文本字符串的代码。看起来像这样(还有更多的IF):

Sub Fix()
  Dim X As Long, Cell As Range
  For Each Cell In Selection
    For X = Len(Cell.Text) To 1 Step -1
      If Cell.Characters(X, 3).Text = ", ," Then Cell.Characters(X, 3).Text = ","
      If Cell.Characters(X, 3).Text = ", (" Then Cell.Characters(X, 3).Text = " ("
      If Cell.Characters(X, 3).Text = ", [" Then Cell.Characters(X, 3).Text = " ["
      If Cell.Characters(X, 3).Text = ", -" Then Cell.Characters(X, 3).Text = " -"
      If Cell.Characters(1, 3).Text = "abc" Then Cell.Characters(1, 3).Text = ""
    Next
  Next
End Sub

我的代码的最后一行删除abc,如果它包含在所选单元格的开头。

我正在寻找如何删除abc(包含在所选单元格的[[末尾中]。

但是对我来说,在单元格中保留所有原始格式(文本大小,颜色,粗体/斜体/下划线字母等)非常重要。

[请记住,我是一个完整的初学者,对编程一无所知。我已经从互联网上复制了上面的代码,只是更改了值。

谢谢您的帮助。

excel vba excel-vba
1个回答
0
投票
类似的事情可能会起作用:
© www.soinside.com 2019 - 2024. All rights reserved.