有没有办法拆分部分文本被删除线的单元格的内容?
Is there a way to split contents of a cell which has part of its text strikenthrough?
我知道如果我检查字体的删除线 属性,例如 range("C1").Font.Strikethrough
如果所有单元格都是删除线和 False
,我将有 True
如果不是,而是在这样的单元格中检查它:
属性 的结果是 Null
。
现在,知道了这一点,有没有办法识别内容单元格的一部分是否是 "strikethrough" 然后解析它以便我可以用其他文本替换?
我知道我可以检查每个字符(检查这个 )是否有 属性 活动但是,我怎么知道文本的哪一部分是删除线然后替换该文本与另一个?
所以我在考虑如何做到这一点,然后想出了以下功能。
Function strkThr(t As Range) As String
Dim i As Long
Dim y As Boolean
Dim temp As String
y = False
temp = ""
For i = 1 To Len(t.Value)
If Not t.Characters(i, 1).Font.Strikethrough = y Then
temp = temp & "|"
If y Then
y = False
Else
y = True
End If
End If
If Not y Then
temp = temp & Mid(t, i, 1)
End If
Next
strkThr = temp
End Function
Sub replace()
Dim cel As Range
For Each cel In Range("A1:A100")
cel.Value = strkThr(cel)
cel.Value = replace(cel.Value, "||", YOURVALUE)
Next cel
End Sub
该函数将每组删除线替换为“||”。然后在子中你会替换“||”与想要的价值。
我知道如果我检查字体的删除线 属性,例如 range("C1").Font.Strikethrough
如果所有单元格都是删除线和 False
,我将有 True
如果不是,而是在这样的单元格中检查它:
属性 的结果是 Null
。
现在,知道了这一点,有没有办法识别内容单元格的一部分是否是 "strikethrough" 然后解析它以便我可以用其他文本替换?
我知道我可以检查每个字符(检查这个
所以我在考虑如何做到这一点,然后想出了以下功能。
Function strkThr(t As Range) As String
Dim i As Long
Dim y As Boolean
Dim temp As String
y = False
temp = ""
For i = 1 To Len(t.Value)
If Not t.Characters(i, 1).Font.Strikethrough = y Then
temp = temp & "|"
If y Then
y = False
Else
y = True
End If
End If
If Not y Then
temp = temp & Mid(t, i, 1)
End If
Next
strkThr = temp
End Function
Sub replace()
Dim cel As Range
For Each cel In Range("A1:A100")
cel.Value = strkThr(cel)
cel.Value = replace(cel.Value, "||", YOURVALUE)
Next cel
End Sub
该函数将每组删除线替换为“||”。然后在子中你会替换“||”与想要的价值。