+ Reply to Thread
Results 1 to 3 of 3

Toggle fill Color in cell based on condition of cell--blank or text added.

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-22-2014
    Location
    Winthrop, ME
    MS-Off Ver
    Excel 2010
    Posts
    420

    Toggle fill Color in cell based on condition of cell--blank or text added.

    Good afternoon. I'm using the following code to fill a cell red if the user exits the cell without choosing a name provided in the drop down list.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        
       If Target.Address <> "$D$3:$E$3" Then
            If Len([D3]) = 0 Then
                Range("$D$3:$E$3").Interior.Color = RGB(255, 0, 0)
                Worksheets("Demographics").Range("E3").Select
            End If
        End If
    End Sub
    If the cell is left blank the fill color changes from the default color (i.e. RGB 196, 189, 151) to RGB (255, 0, 0). What I can't figure out is how to toggle the color from 255, 0, 0 (red) back to the default color 196, 189, 151 (greyish-brown). Thanks for any help you might be able to provide.

    Matthew

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,651

    Re: Toggle fill Color in cell based on condition of cell--blank or text added.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        
       If Target.Address <> "$D$3:$E$3" Then
            If Len([D3]) = 0 Then
                Range("$D$3:$E$3").Interior.Color = RGB(255, 0, 0)
                Worksheets("Demographics").Range("E3").Select
            Else
                Range("$D$3:$E$3").Interior.Color = RGB(196, 189, 151)
            End If
        End If
    End Sub
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor
    Join Date
    02-22-2014
    Location
    Winthrop, ME
    MS-Off Ver
    Excel 2010
    Posts
    420

    Re: Toggle fill Color in cell based on condition of cell--blank or text added.

    AlphaFrog,

    Once again, thanks for the addition to the code. It works perfectly. Thanks.

    Matthew

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macro to change cell text color based on darkness of cell fill color
    By cincyshirm61 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-25-2014, 12:11 PM
  2. Condition based on Cell Text Color
    By yogesh1904 in forum Excel General
    Replies: 2
    Last Post: 09-09-2012, 11:21 AM
  3. Color fill a cell and then remove the color when a date is added.
    By texas tornado in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-25-2012, 02:14 AM
  4. Toggle Text Color in Cell A, when Cell B clicked...
    By woodman650 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-04-2008, 02:22 AM
  5. Replies: 4
    Last Post: 01-12-2006, 09:50 AM

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