Set text color to interior color

G

Guest

I have the following code:

Sub Test1()
Dim MyRange As Range
Dim MyColor As Integer
Dim MyCell As Integer

'' set range = to selected cells ''
Set MyRange = Selection

'' evaluate the value and apply to appropriate text color ''
For Each c In MyRange
c.Select
MyCell = ActiveCell.Value
Select Case MyCell
Case 0
Selection.Font.ColorIndex = 0
Case Else
Selection.Font.ColorIndex = 3
End Select
Next
End Sub

This code works fabulously, however, I would like to set the font colorindex
to the same value as the interior color index if the cell value is 0. Is
this possible, and how would I go about this ?
 
D

Don Guillett

try this
Sub docolors()
Selection.Font.ColorIndex = 3
For Each c In Selection
If c = 0 Then c.Font.ColorIndex = _
c.Interior.ColorIndex
Next c
End Sub
 
G

Guest

This worked, I also tried a slight tweak to my own code, seting mycolor = to
the interior color and then if the value is o set the font colorindex = to
mycolor:

Thanks!

Sub Change_Color()
Dim MyRange As Range
Dim MyColor As Integer
Dim MyCell As Integer

MyColor = Selection.Interior.ColorIndex
Debug.Print MyColor
'' set range = to selected cells ''
Set MyRange = Selection

'' evaluate the value and apply to appropriate text color ''
For Each c In MyRange
c.Select
MyCell = ActiveCell.Value
Select Case MyCell
Case 0
Selection.Font.ColorIndex = MyColor
Case Else
Selection.Font.ColorIndex = 0
End Select
Next
End Sub
 
G

Guest

Help me understand what was unnecessary / undesirable ... I'm pretty new at
this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top