Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default conditional formatting vba code and calculation

trying to apply conditional formatting to rows based on a cell's formula results, using vba code. (there are more than three conditions, so i can't use conditional formatting).

i got the following code through a previous post that works ok if i go to the cell with the formula, edit the text, then press return to update the results... however, if instead, i change one of the values that the formula is based on (in order to test the result with a different value), the formatting is not updated.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range

Set rng = Intersect(Target, Range("S:S"))
If rng Is Nothing Then
Exit Sub
Else
Dim cl As Range

For Each cl In rng
Select Case cl.Text
Case "Closed"
cl.EntireRow.Interior.ColorIndex = 35
Case "Canceled"
cl.EntireRow.Interior.ColorIndex = 40
Case "Open Mod"
cl.EntireRow.Interior.ColorIndex = 36
Case "New Award"
cl.EntireRow.Interior.ColorIndex = 34
Case Else
cl.EntireRow.Interior.ColorIndex = 0

Exit Sub
End Select
Next cl
End If

End Sub

Anyone know how to make this work?

TIA!
Jill.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default conditional formatting vba code and calculation

Changing a cell that is not within that range will not trigger the change
event. The best you can do is to test the calculate event, but then you
would need some algorithm for determining how much of column S that you
want to update.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Jill" wrote in message
...
trying to apply conditional formatting to rows based on a cell's formula

results, using vba code. (there are more than three conditions, so i can't
use conditional formatting).

i got the following code through a previous post that works ok if i go to

the cell with the formula, edit the text, then press return to update the
results... however, if instead, i change one of the values that the formula
is based on (in order to test the result with a different value), the
formatting is not updated.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range

Set rng = Intersect(Target, Range("S:S"))
If rng Is Nothing Then
Exit Sub
Else
Dim cl As Range

For Each cl In rng
Select Case cl.Text
Case "Closed"
cl.EntireRow.Interior.ColorIndex = 35
Case "Canceled"
cl.EntireRow.Interior.ColorIndex = 40
Case "Open Mod"
cl.EntireRow.Interior.ColorIndex = 36
Case "New Award"
cl.EntireRow.Interior.ColorIndex = 34
Case Else
cl.EntireRow.Interior.ColorIndex = 0

Exit Sub
End Select
Next cl
End If

End Sub

Anyone know how to make this work?

TIA!
Jill.



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
Date Calculation & Conditional Formatting Stumped Excel Discussion (Misc queries) 3 August 7th 09 09:58 PM
Date Calculation in Conditional Formatting JPS Excel Worksheet Functions 2 July 23rd 08 08:35 AM
Conditional Formatting using code Ayo Excel Discussion (Misc queries) 5 February 29th 08 01:09 PM
Override conditional formatting with code Sarah Excel Discussion (Misc queries) 4 April 30th 07 08:28 PM
Macro code to delete conditional formatting Bovine Jones Excel Discussion (Misc queries) 5 October 19th 06 08:39 AM


All times are GMT +1. The time now is 03:12 AM.

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"