[英]Excel VBA: Delete strikethrough characters in a cell
我有大約1000行數據。 一些單元格由刪除線和普通字符組成。 我只想刪除那些刪除線字符,並在這些單元格中保留其他非刪除線字符。 單元的其余部分也應保持原樣。
單元格中的示例:
“ 334(刪除線)124”
該代碼應將單元格值更改為:
“ 124”
而不刪除整個單元格。
嘗試這個
Sub Macro1()
Dim oCell As Range, i%, z%
For Each oCell In Range("A1:A6")
z = Len(oCell.Value)
i = 1
While z <> 0
If oCell.Characters(Start:=i, Length:=1).Font.Strikethrough = True Then
oCell.Characters(Start:=i, Length:=1).Caption = ""
i = i - 1
End If
i = i + 1
z = z - 1
Wend
Next
End Sub
從Characters
刪除時,從右到左循環更容易:
Sub Demo()
Dim rng As Range, cl As Range
Dim i As Long
Set rng = [A1:A3] ' Get range of interest
For Each cl In rng.Cells
For i = Len(cl.Value) To 1 Step -1
If cl.Characters(i, 1).Font.Strikethrough Then
cl.Characters(i, 1).Delete
End If
Next i, cl
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.