Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Strikethrough Red and Underline Blue Macro


I have successfully written a Macro in Word to change the font color of
all text that has a strikethrough to red and all text that has an
underline I change the font to blue.

Can someone help me out with an Excel Macro like this? Keep in mind a
cell can contain text that has both underlined text and strikethrough
text within it.


--
Rainman76
------------------------------------------------------------------------
Rainman76's Profile: http://www.excelforum.com/member.php...o&userid=26091
View this thread: http://www.excelforum.com/showthread...hreadid=394182

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Strikethrough Red and Underline Blue Macro

Sub StrikeRedUnderBlue(ByVal Target As Range)

Dim CCell As Range, Char As Integer

For Each CCell In Target
With CCell
For Char = 1 To .Characters.Count
If .Characters(Char).Font.Strikethrough _
Then .Characters(Char).Font.Color = vbRed
If .Characters(Char).Font.Underline < xlUnderlineStyleNone _
Then .Characters(Char).Font.Color = vbBlue
Next Char
End With
Next CCell

End Sub
--
- K Dales


"Rainman76" wrote:


I have successfully written a Macro in Word to change the font color of
all text that has a strikethrough to red and all text that has an
underline I change the font to blue.

Can someone help me out with an Excel Macro like this? Keep in mind a
cell can contain text that has both underlined text and strikethrough
text within it.


--
Rainman76
------------------------------------------------------------------------
Rainman76's Profile: http://www.excelforum.com/member.php...o&userid=26091
View this thread: http://www.excelforum.com/showthread...hreadid=394182


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Strikethrough Red and Underline Blue Macro

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

"Rainman76" wrote
in message ...

I have successfully written a Macro in Word to change the font color of
all text that has a strikethrough to red and all text that has an
underline I change the font to blue.

Can someone help me out with an Excel Macro like this? Keep in mind a
cell can contain text that has both underlined text and strikethrough
text within it.


--
Rainman76
------------------------------------------------------------------------
Rainman76's Profile:

http://www.excelforum.com/member.php...o&userid=26091
View this thread: http://www.excelforum.com/showthread...hreadid=394182



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Strikethrough Red and Underline Blue Macro

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" <peter_t@discussions wrote in message
...
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

"Rainman76" wrote
in message ...

I have successfully written a Macro in Word to change the font color of
all text that has a strikethrough to red and all text that has an
underline I change the font to blue.

Can someone help me out with an Excel Macro like this? Keep in mind a
cell can contain text that has both underlined text and strikethrough
text within it.


--
Rainman76
------------------------------------------------------------------------
Rainman76's Profile:

http://www.excelforum.com/member.php...o&userid=26091
View this thread:

http://www.excelforum.com/showthread...hreadid=394182





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
IF Strikethrough lightbulb Excel Discussion (Misc queries) 5 April 4th 23 02:11 PM
Borders nor underline commands remove an unusual underline. ?? VideoFreak Excel Discussion (Misc queries) 4 February 11th 06 08:17 PM
formatting (underline/bold/strikethrough) in comment boxes adam l via OfficeKB.com Excel Discussion (Misc queries) 3 November 8th 05 05:55 PM
Strikethrough and Underline Font Macro Rainman Excel Worksheet Functions 0 August 9th 05 01:32 PM
Strikethough and Underline Macro Rainman Excel Worksheet Functions 0 August 9th 05 01:31 PM


All times are GMT +1. The time now is 05:10 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"