Ignore previous, somehow I pasted completely wrong code which was part draft
of the following, which I intended to post first time. These things happen!
Sub test()
Dim X As Long
Dim cel As Range
Dim ch As Font
Dim vst, vun
For Each cel In Selection
X = FntFormat(cel.Font)
If X = 0 Then
For i = 1 To Len(cel)
cel.Characters(i, 1).Font.ColorIndex = _
FntFormat(cel.Characters(i, 1).Font)
Next
Else
cel.Font.ColorIndex = X
End If
Next
End Sub
Function FntFormat(fnt As Font) As Long
Dim v1, v2
Dim X As Long
v1 = fnt.Strikethrough
v2 = (fnt.Underline <> xlUnderlineStyleNone)
If IsNull(v1) Or IsNull(v2) Then
X = 0
Else
X = xlAutomatic
If v1 Then X = 3
If v2 Then
If X > 0 Then X = 13 Else X = 5
End If
End If
FntFormat = X
End Function
Peter T
Peter T said:
So what colour do you want if both strikethrough & underline. As you didn't
specify the following will colour font
- strikethrough to red
- underline to blue
- strikethrough + underline to violet
- not strickthrough & not underline to system black (automatic)
Start by selecting the cells you want processed
Sub test()
Dim X As Long
Dim cel As Range
Dim ch As Font
Dim vst, vun
For Each cel In Selection
X = 0
If FntFormat(cel.Font) = 0 Then
For i = 1 To Len(cel)
cel.Characters(i, 1).Font.ColorIndex = _
FntFormat(cel.Characters(i, 1).Font)
Next
Else
cel.ColorIndex = X
End If
Next
End Sub
Function FntFormat(fnt As Font) As Long
Dim v1, v2
Dim X As Long
v1 = fnt.Strikethrough
v2 = (fnt.Underline <> xlUnderlineStyleNone)
If IsNull(v1) Or IsNull(v2) Then
X = 0
Else
X = xlAutomatic
If v1 Then X = 3
If v2 Then
If X Then X = 13 Else X = 5
End If
End If
FntFormat = X
End Function
You message implied there might be mixed formats in the same cell, the above
should cater for that possibility. If not it's overkill.
Regards,
Peter T