+ Reply to Thread
Results 1 to 3 of 3

Cell Colour based on text in Range of cells

  1. #1
    Registered User
    Join Date
    03-02-2006
    Posts
    11

    Cell Colour based on text in Range of cells

    Hi!

    I'm not too familiar with VBA, so i was hoping someone could please help me!

    I want to change the background colour of a single cell, based on the text in a range of cells (which can be one of two options.) I want the cell colour of F14 to change if all the cells in G14:S14 contain either "N/A" or a date timestamp. This is what i tried out:

    Private Sub Worksheet_Change(ByVal Target As Range)

    Dim icolor As Integer


    If Not Intersect(Target, Range("G14:S14")) Is Nothing Then
    If Range("G14:S14").Text = "N/A" Or "date value" Then

    Range("F14").Interior.ColorIndex = 4
    Else
    Range("F14").Interior.ColorIndex = 0
    End If
    End If

    End Sub

    This pretty much does the job, but the Or condition doesnt work. Any help would be much appreciated!! Thanks!!

  2. #2
    Tom Ogilvy
    Guest

    Re: Cell Colour based on text in Range of cells

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim bOk as Boolean, cell as Range
    Dim icolor As Integer
    If Not Intersect(Target, Range("G14:S14")) Is Nothing Then
    bOk = True

    for each cell in Range("G14:S14")
    if not isdate(cell.Value) then
    if cell.Text <> "N/A" then
    bOK = False
    exit for
    end if
    end if
    Next
    If bOk then
    Range("F14").Interior.ColorIndex = 4
    Else
    Range("F14").Interior.ColorIndex = 0
    End If
    End if

    End Sub

    --
    Regards,
    Tom Ogilvy

    "viewmaster" <viewmaster.242e1o_1141340103.8546@excelforum-nospam.com> wrote
    in message news:viewmaster.242e1o_1141340103.8546@excelforum-nospam.com...
    >
    > Hi!
    >
    > I'm not too familiar with VBA, so i was hoping someone could please
    > help me!
    >
    > I want to change the background colour of a single cell, based on the
    > text in a range of cells (which can be one of two options.) I want the
    > cell colour of F14 to change if *all* the cells in G14:S14 contain
    > either "N/A" or a date timestamp. This is what i tried out:
    >
    > Private Sub Worksheet_Change(ByVal Target As Range)
    >
    > Dim icolor As Integer
    >
    >
    > If Not Intersect(Target, Range("G14:S14")) Is Nothing Then
    > If Range("G14:S14").Text = "N/A" Or "date value" Then
    >
    > Range("F14").Interior.ColorIndex = 4
    > Else
    > Range("F14").Interior.ColorIndex = 0
    > End If
    > End If
    >
    > End Sub
    >
    > This pretty much does the job, but the Or condition doesnt work. Any
    > help would be much appreciated!! Thanks!!
    >
    >
    > --
    > viewmaster
    > ------------------------------------------------------------------------
    > viewmaster's Profile:

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




  3. #3
    Registered User
    Join Date
    03-02-2006
    Posts
    11
    Thank you soooo much! It works a charm!!

+ 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