Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default changing a cell to different colors

I have an excel worksheet that i am trying to code to make it cycle through 3
different colors (yellow, green and red) by double clicking on the cell, all
it does is keep it blank....here is the code that i have in the sheet right
now. As well i would like this to apply to only certain cells, (i dont know
how to define the range, its been a really long time since i worked with this)
HELP!!!


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
If ActiveCell.Interior.ColorIndex = xlNone Then
ActiveCell.Interior.ColorIndex = 6
End If
If ActiveCell.Interior.ColorIndex = 6 Then
ActiveCell.Interior.ColorIndex = 4
End If
If ActiveCell.Interior.ColorIndex = 4 Then
ActiveCell.Interior.ColorIndex = 3
End If
If ActiveCell.Interior.ColorIndex = 3 Then
ActiveCell.Interior.ColorIndex = xlNone
End If
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default changing a cell to different colors

Hi jobobak

I think your code must be cycling through all the colours and arriving back
at a blank cell. Try this:


If Target.Interior.ColorIndex = xlNone Then
Target.Interior.ColorIndex = 6
ElseIf Target.Interior.ColorIndex = 6 Then
Target.Interior.ColorIndex = 4
ElseIf Target.Interior.ColorIndex = 4 Then
Target.Interior.ColorIndex = 3
Else: Target.Interior.ColorIndex = 3
Target.Interior.ColorIndex = xlNone
End If



"jbobak" <u59798@uwe wrote in message news:a783e847dfce5@uwe...
I have an excel worksheet that i am trying to code to make it cycle

through 3
different colors (yellow, green and red) by double clicking on the cell,

all
it does is keep it blank....here is the code that i have in the sheet

right
now. As well i would like this to apply to only certain cells, (i dont

know
how to define the range, its been a really long time since i worked with

this)
HELP!!!


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
If ActiveCell.Interior.ColorIndex = xlNone Then
ActiveCell.Interior.ColorIndex = 6
End If
If ActiveCell.Interior.ColorIndex = 6 Then
ActiveCell.Interior.ColorIndex = 4
End If
If ActiveCell.Interior.ColorIndex = 4 Then
ActiveCell.Interior.ColorIndex = 3
End If
If ActiveCell.Interior.ColorIndex = 3 Then
ActiveCell.Interior.ColorIndex = xlNone
End If
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default changing a cell to different colors

If you only want certain ranges to be affected use

Set isect = Application.Intersect(Target, Range("$A$6")) << change as needed
If Not isect Is Nothing Then
If Target.Interior.ColorIndex = xlNone Then
Target.Interior.ColorIndex = 6
ElseIf Target.Interior.ColorIndex = 6 Then
Target.Interior.ColorIndex = 4
ElseIf Target.Interior.ColorIndex = 4 Then
Target.Interior.ColorIndex = 3
Else: Target.Interior.ColorIndex = 3
Target.Interior.ColorIndex = xlNone
End If
End If



"jbobak" <u59798@uwe wrote in message news:a783e847dfce5@uwe...
I have an excel worksheet that i am trying to code to make it cycle

through 3
different colors (yellow, green and red) by double clicking on the cell,

all
it does is keep it blank....here is the code that i have in the sheet

right
now. As well i would like this to apply to only certain cells, (i dont

know
how to define the range, its been a really long time since i worked with

this)
HELP!!!


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
If ActiveCell.Interior.ColorIndex = xlNone Then
ActiveCell.Interior.ColorIndex = 6
End If
If ActiveCell.Interior.ColorIndex = 6 Then
ActiveCell.Interior.ColorIndex = 4
End If
If ActiveCell.Interior.ColorIndex = 4 Then
ActiveCell.Interior.ColorIndex = 3
End If
If ActiveCell.Interior.ColorIndex = 3 Then
ActiveCell.Interior.ColorIndex = xlNone
End If
End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing cell colors Joebeone Excel Discussion (Misc queries) 1 February 11th 10 07:17 PM
changing colors of a cell Ben Excel Programming 1 February 13th 07 11:09 PM
Changing cell colors in a row IF... Debra Dalgleish Excel Programming 0 January 15th 07 10:46 PM
Changing cell colors in a row IF... Ken Excel Programming 0 January 15th 07 10:21 PM
Changing the colors of a cell Keith Excel Programming 1 November 24th 04 01:41 PM


All times are GMT +1. The time now is 01:29 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"