我有部分删除线的单元格。为了更容易阅读,我想删除它。
我找到了这个VBA,但它不保留颜色或粗体字符。
你能帮我吗?
PS:所有带文本的单元格均以'
开头
Sub DelStrikethroughText()
Dim xRg As Range, xCell As Range
Dim xStr As String
Dim I As Long
On Error Resume Next
Set xRg = Application.InputBox("Please select range:", "KuTools For Excel", Selection.Address, , , , , 8)
If xRg Is Nothing Then Exit Sub
Application.ScreenUpdating = Fase
For Each xCell In xRg
If IsNumeric(xCell.Value) And xCell.Font.Strikethrough Then
xCell.Value = ""
ElseIf Not IsNumeric(xCell.Value) Then
For I = 1 To Len(xCell)
With xCell.Characters(I, 1)
If Not .Font.Strikethrough Then
xStr = xStr & .Text
End If
End With
Next
xCell.Value = xStr
xStr = ""
End If
Next
Application.ScreenUpdating = True
End Sub
1条答案
按热度按时间qmelpv7a1#
您无法在不丢失任何每字符格式的情况下替换单元格中带有部分格式的值。
如果需要删除文本,请使用
Characters()
方法。