Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Worksheet change doesn't work completely

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

I've got this function for each cell in the range "n7:is66"....

=IF(AND(N$2=$K7,N$2<=$L7),IF($G7="On Track",2,IF($G7="Issues",
3,IF($G7="At Risk",4,IF($G7="Completed",5,1)))),"")

and because conditional formating is too limited, I've got the below
VBA changing the colors when $G7 through $G66 changes, it works fine
when g7 is changed, but in order for the cells in n7:is66 to chang
color, I have to click each one individually in order for them to
change to their new color. So, how can these cells change color
everytime colomn G on their row changes automatically?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Not Intersect(Target, Range("n7:is66")) Is Nothing Then
Select Case Target
Case 1
icolor = 41
Case 2
icolor = 10
Case 3
icolor = 6
Case 4
icolor = 3
Case 5
icolor = 1
Case Else
'whatever
End Select
End If
Target.Interior.ColorIndex = icolor

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Worksheet change doesn't work completely

Try putting your macro in the worksheet_change event instead of the
wotksheet_Selectionchange that you have it in now.

Mike

" wrote:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

I've got this function for each cell in the range "n7:is66"....

=IF(AND(N$2=$K7,N$2<=$L7),IF($G7="On Track",2,IF($G7="Issues",
3,IF($G7="At Risk",4,IF($G7="Completed",5,1)))),"")

and because conditional formating is too limited, I've got the below
VBA changing the colors when $G7 through $G66 changes, it works fine
when g7 is changed, but in order for the cells in n7:is66 to chang
color, I have to click each one individually in order for them to
change to their new color. So, how can these cells change color
everytime colomn G on their row changes automatically?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Not Intersect(Target, Range("n7:is66")) Is Nothing Then
Select Case Target
Case 1
icolor = 41
Case 2
icolor = 10
Case 3
icolor = 6
Case 4
icolor = 3
Case 5
icolor = 1
Case Else
'whatever
End Select
End If
Target.Interior.ColorIndex = icolor

End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Worksheet change doesn't work completely


When I use Private Sub Worksheet_Change the cell will not change at
all, when I noticed that it at least changes if I click on it when
using the SelectionChange, i just left it. I'm very new at any
coding. So, I thank you for your help.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Worksheet change doesn't work completely

Since those cells each contain formulas, the worksheet_Change event won't help
either.

But you could use the worksheet_Calculate event (still behind that worksheet).

Option Explicit
Private Sub Worksheet_Calculate()

Dim myCell As Range
Dim myRng As Range
Dim iColor As Long

Set myRng = Me.Range("N7:is66")

For Each myCell In myRng.Cells
Select Case myCell.Value
Case 1: iColor = 41
Case 2: iColor = 10
Case 3: iColor = 6
Case 4: iColor = 3
Case 5: iColor = 1
Case Else
'whatever
End Select
myCell.Interior.ColorIndex = iColor
Next myCell

End Sub


Be aware that with this many cells, you may find that each calculation takes
longer that you expect.

wrote:

When I use Private Sub Worksheet_Change the cell will not change at
all, when I noticed that it at least changes if I click on it when
using the SelectionChange, i just left it. I'm very new at any
coding. So, I thank you for your help.


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Worksheet change doesn't work completely

Okay this works good, it does take a few seconds to update, but I'm
okay with it.Thanks.....
But, the cells in this range have stopped refering to the AND
statement below ...

=IF(AND(N$2=$K7,N$2<=$L7),IF($G7="On Track",2,IF($G7="Issues",
3,IF($G7="At Risk",4,IF($G7="Completed",5,1)))),"")

there is a begining date and an ending date for each row. In the
range N7:is66 each cell represents a day. if the day that each cell
represents doesn't fall between the date range, then it is not
colored. The code you helped me with stopped doing this. It's
ignoring the dates that the AND statement is refering to above....


Adam

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
how do I get my Data tab to work? It is completely greyed out. calmlysmile Excel Discussion (Misc queries) 1 June 6th 09 10:31 PM
Changing Worksheet State completely huysmans Excel Programming 1 September 27th 06 05:53 PM
worksheet change doesn't always work damorrison Excel Discussion (Misc queries) 1 May 29th 06 11:38 AM
worksheet change event doesn't work gig Excel Programming 3 March 20th 05 02:18 PM
Amend code or change it completely? Gareth[_3_] Excel Programming 2 December 1st 03 07:24 PM


All times are GMT +1. The time now is 07:14 PM.

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

About Us

"It's about Microsoft Excel"