I know if I check the strikethrough property of Font like, for example range("C1").Font.Strikethrough
I'll have True
if all the cell is strikethrough and a False
if it's not but checking it in a cell like this:
The result of the property is Null
.
Now, knowing this, is there a way to recognize if just part of the content cell is "strikethrough" and then parse it so I could replace with other text?
I know I can check each character (checked out this example) if it has the property active but, how could I know which part of the text is strikethrough and then replacing that text with another one?
So I was thinking about how I would do this and I came up with the following function.
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
The function replaces each grouping of strike through text with "||". Then in the sub you would replace the "||" with the value wanted.