+ Reply to Thread
Results 1 to 2 of 2

Macro to change cell text color

  1. #1
    Registered User
    Join Date
    07-22-2004
    Posts
    89

    Macro to change cell text color

    OBJECTIVE: I select a range of cells. I want a macro I can run that changes the color of the text based on 3 criteria:
    (1) if a numeric value w/o an = sign or any mathematical operators, then RED
    (2) if a forumla w/ an = sign, but no other operators, then GREEN
    (3) if a formula w/ an = sign and operators, then BLUE

    Can anyone post this?

    Thanks.

    - Jim

  2. #2
    Bob Phillips
    Guest

    Re: Macro to change cell text color

    Jim,

    Here's a shot

    Dim cell As Range
    Dim sFormula As String

    For Each cell In Selection
    If cell.HasFormula Then
    sFormula =
    "SUMPRODUCT(--(ISNUMBER(SEARCH({""+"",""-"",""~*"",""/"",""^""},""" &
    cell.Formula & """))))"
    If Evaluate(sFormula) > 0 Then
    cell.Interior.ColorIndex = 5
    Else
    cell.Interior.ColorIndex = 10
    End If
    Else
    If IsNumeric(cell.Value) Then
    cell.Interior.ColorIndex = 3
    End If
    End If
    Next cell

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "James C" <[email protected]> wrote in
    message news:[email protected]...
    >
    > OBJECTIVE: I select a range of cells. I want a macro I can run that
    > changes the color of the text based on 3 criteria:
    > (1) if a numeric value w/o an = sign or any mathematical operators,
    > then RED
    > (2) if a forumla w/ an = sign, but no other operators, then GREEN
    > (3) if a formula w/ an = sign and operators, then BLUE
    >
    > Can anyone post this?
    >
    > Thanks.
    >
    > - Jim
    >
    >
    > --
    > James C
    > ------------------------------------------------------------------------
    > James C's Profile:

    http://www.excelforum.com/member.php...o&userid=12114
    > View this thread: http://www.excelforum.com/showthread...hreadid=395347
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1