Re: Set text color to interior color

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Your code uses unnecessary/undesirable selections.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
dguillett1@xxxxxxxxxxxxx
"KJ-clueless" <KJclueless@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:423FA18F-58CF-4066-9F02-C62E42E042EF@xxxxxxxxxxxxxxxx
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


"Don Guillett" wrote:

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

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
dguillett1@xxxxxxxxxxxxx
"KJ-clueless" <KJclueless@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:9CE1BFD4-33D9-4D2A-AA60-0249B3D5CC9D@xxxxxxxxxxxxxxxx
>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 ?



.



Relevant Pages

  • Re: Frequency FormulaArray Syntax
    ... Juan, if possible could you explain to a novice: ... I understand the selection of rows and the assignment of MyRange. ... > Dim MyFormula As String ...
    (microsoft.public.excel.worksheet.functions)
  • Re: How to replace a string of characters with the count of the ch
    ... Dim AlphabetCountString As String ... I prefer to work with Range objects instead of the Selection whenever ... .MatchWildcards = False ...
    (microsoft.public.word.vba.general)
  • Ws Selection Change Event Code, Copy a Cell problem
    ... The sub below is doing what I want, re: selection. ... Dim RngType As String ... If ChgRow> PaEndRow Then ... Cells(ChgRow, SVrSubscrCol + COfs).Select ...
    (microsoft.public.excel.programming)
  • RE: Emailing With Attachments
    ... Presenting the file list in a combo box for selection ... Dim fso As New FileSystemObject ... 'Try to extract JobNum in the File name ... 'Set objOutlookRecip = .Recipients.Add ...
    (microsoft.public.access.modulesdaovba)
  • Re: Moving to next field with F11 in protected document
    ... macro is invoked with a keyboard hotkey and looks at the characters to ... a file with the name of the selection and inserts one space and then ... Dim rgeField As Range ... Dim lngStart As Long ...
    (microsoft.public.word.vba.beginners)