Results 1 to 1 of 1

Excel 2007 : Change color of cell on click

Threaded View

  1. #1
    Registered User
    Join Date
    12-08-2011
    Location
    Portland Oregon
    MS-Off Ver
    Excel 2007
    Posts
    1

    Change color of cell on click

    I am attempting to program an excell sheet so that some of the rows change one set of colors when selected while the rest of the rows will change a different set of colors.

    Example:

    Rows 1,3,5,9 will change red, then, bule, then green

    Rows 2,4,6,8 will change Purple, then yellow when clicked.

    This is what I have done so far:

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
        
     ' This subroutine colors a cell red when double-clicked then clears it when double-clicked again.
     ' Some values for .ColorIndex are...
     ' Red = 3, Green = 4, Blue = 5, Yellow = 6, Orange = 45
     ' Google "VBA color palette" for more colors
      
         ' If the cell is clear
         If Target.Interior.ColorIndex = xlNone Then
      ' Then change the background color to red
             
             Target.Interior.ColorIndex = 21
      
         ' Else if the cell background color is red
         ElseIf Target.Interior.ColorIndex = 21 Then
      
      ' Then clear the background
             Target.Interior.ColorIndex = 23
             
             ' Else if the cell background color is red
         ElseIf Target.Interior.ColorIndex = 23 Then
             
             ' Then change the background color to red
             Target.Interior.ColorIndex = 10
      
         ' Else if the cell background color is red
         ElseIf Target.Interior.ColorIndex = 10 Then
              
             ' Then clear the background
             Target.Interior.ColorIndex = xlNone
      
         End If
    '
    Last edited by Paul; 12-14-2011 at 02:07 PM. Reason: Added CODE tags for new user. Please read the forum rules.

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