PC Review


Reply
Thread Tools Rate Thread

Conditional Formatting- Refresh

 
 
Ram B
Guest
Posts: n/a
 
      2nd Jul 2008
I have added a VB script to a sheet to change color of the cell based on input
Private Sub Worksheet_Change(ByVal Target As Range)
Dim icolor As Integer

If Not Intersect(Target, Range("F1:F510")) Is Nothing Then
Select Case Target
Case "Red"
icolor = 3
Case "Green"
icolor = 4
Case "Blue"
icolor = 5
Case "White"
icolor = 2
Case "Gray"
icolor = 15
Case ""
icolor = 0
Case Else
'Whatever
End Select

Target.Interior.ColorIndex = icolor
Target.Font.ColorIndex = icolor

End If

End Sub
---------------------------------------------------
This works well if the data is entered manually.
some cells that have a calculated input using a formula does not get
updated. It works if I use "Conditional Formatting" but the limitation there
is 3 colours. Any help will be appreciated.

 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      2nd Jul 2008
Use the calculate event and cycle through each cell in the range.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Ram B" <(E-Mail Removed)> wrote in message
news:6717DF5B-3C5E-4383-AE8C-(E-Mail Removed)...
>I have added a VB script to a sheet to change color of the cell based on
>input
> Private Sub Worksheet_Change(ByVal Target As Range)
> Dim icolor As Integer
>
> If Not Intersect(Target, Range("F1:F510")) Is Nothing Then
> Select Case Target
> Case "Red"
> icolor = 3
> Case "Green"
> icolor = 4
> Case "Blue"
> icolor = 5
> Case "White"
> icolor = 2
> Case "Gray"
> icolor = 15
> Case ""
> icolor = 0
> Case Else
> 'Whatever
> End Select
>
> Target.Interior.ColorIndex = icolor
> Target.Font.ColorIndex = icolor
>
> End If
>
> End Sub
> ---------------------------------------------------
> This works well if the data is entered manually.
> some cells that have a calculated input using a formula does not get
> updated. It works if I use "Conditional Formatting" but the limitation
> there
> is 3 colours. Any help will be appreciated.
>



 
Reply With Quote
 
Alan
Guest
Posts: n/a
 
      2nd Jul 2008
The reason it does not change the cell with the formula is because it is not
the "target" cell, but is only affected by the "target" cell.

I don't know what version you are running. I am running 2002. In 2002
Conditional Formatting has all the Excel standard colors, not just 3.

Format
Conditional Formatting
Click the Format button
Click the Pattern tab.
All Excel standard colors are available here.

Conditional Formatting is the easiest way to go. You could calculate each
cell in the range after a change occurs.


Alan



"Ram B" wrote:

> I have added a VB script to a sheet to change color of the cell based on input
> Private Sub Worksheet_Change(ByVal Target As Range)
> Dim icolor As Integer
>
> If Not Intersect(Target, Range("F1:F510")) Is Nothing Then
> Select Case Target
> Case "Red"
> icolor = 3
> Case "Green"
> icolor = 4
> Case "Blue"
> icolor = 5
> Case "White"
> icolor = 2
> Case "Gray"
> icolor = 15
> Case ""
> icolor = 0
> Case Else
> 'Whatever
> End Select
>
> Target.Interior.ColorIndex = icolor
> Target.Font.ColorIndex = icolor
>
> End If
>
> End Sub
> ---------------------------------------------------
> This works well if the data is entered manually.
> some cells that have a calculated input using a formula does not get
> updated. It works if I use "Conditional Formatting" but the limitation there
> is 3 colours. Any help will be appreciated.
>

 
Reply With Quote
 
Ram B
Guest
Posts: n/a
 
      2nd Jul 2008

I am engineer with little knowledge of VB. Would it be possible for you to
help me with the code?
"Bob Phillips" wrote:

> Use the calculate event and cycle through each cell in the range.
>
> --
> HTH
>
> Bob
>
> (there's no email, no snail mail, but somewhere should be gmail in my addy)
>
> "Ram B" <(E-Mail Removed)> wrote in message
> news:6717DF5B-3C5E-4383-AE8C-(E-Mail Removed)...
> >I have added a VB script to a sheet to change color of the cell based on
> >input
> > Private Sub Worksheet_Change(ByVal Target As Range)
> > Dim icolor As Integer
> >
> > If Not Intersect(Target, Range("F1:F510")) Is Nothing Then
> > Select Case Target
> > Case "Red"
> > icolor = 3
> > Case "Green"
> > icolor = 4
> > Case "Blue"
> > icolor = 5
> > Case "White"
> > icolor = 2
> > Case "Gray"
> > icolor = 15
> > Case ""
> > icolor = 0
> > Case Else
> > 'Whatever
> > End Select
> >
> > Target.Interior.ColorIndex = icolor
> > Target.Font.ColorIndex = icolor
> >
> > End If
> >
> > End Sub
> > ---------------------------------------------------
> > This works well if the data is entered manually.
> > some cells that have a calculated input using a formula does not get
> > updated. It works if I use "Conditional Formatting" but the limitation
> > there
> > is 3 colours. Any help will be appreciated.
> >

>
>
>

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      2nd Jul 2008
Here you are

Private Sub Worksheet_Calculate()
Dim icolor1 As Long
Dim icolor2 As Long
Dim cell As Range

For Each cell In Range("F1:F510")

icolor1 = xlColorIndexNone
icolor2 = xlColorIndexAutomatic
Select Case cell.Value
Case "Red": icolor1 = 3: icolor2 = 3
Case "Green": icolor1 = 4: icolor2 = 4
Case "Blue": icolor1 = 5: icolor2 = 5
Case "White": icolor1 = 2: icolor2 = 2
Case "Gray": icolor1 = 15: icolor2 = 15
Case Else: 'Whatever
End Select

cell.Interior.ColorIndex = icolor1
cell.Font.ColorIndex = icolor2
Next cell

End Sub


--
__________________________________
HTH

Bob

"Ram B" <(E-Mail Removed)> wrote in message
news:02ABD4B8-B833-45FF-8105-(E-Mail Removed)...
>
> I am engineer with little knowledge of VB. Would it be possible for you
> to
> help me with the code?
> "Bob Phillips" wrote:
>
>> Use the calculate event and cycle through each cell in the range.
>>
>> --
>> HTH
>>
>> Bob
>>
>> (there's no email, no snail mail, but somewhere should be gmail in my
>> addy)
>>
>> "Ram B" <(E-Mail Removed)> wrote in message
>> news:6717DF5B-3C5E-4383-AE8C-(E-Mail Removed)...
>> >I have added a VB script to a sheet to change color of the cell based on
>> >input
>> > Private Sub Worksheet_Change(ByVal Target As Range)
>> > Dim icolor As Integer
>> >
>> > If Not Intersect(Target, Range("F1:F510")) Is Nothing Then
>> > Select Case Target
>> > Case "Red"
>> > icolor = 3
>> > Case "Green"
>> > icolor = 4
>> > Case "Blue"
>> > icolor = 5
>> > Case "White"
>> > icolor = 2
>> > Case "Gray"
>> > icolor = 15
>> > Case ""
>> > icolor = 0
>> > Case Else
>> > 'Whatever
>> > End Select
>> >
>> > Target.Interior.ColorIndex = icolor
>> > Target.Font.ColorIndex = icolor
>> >
>> > End If
>> >
>> > End Sub
>> > ---------------------------------------------------
>> > This works well if the data is entered manually.
>> > some cells that have a calculated input using a formula does not get
>> > updated. It works if I use "Conditional Formatting" but the limitation
>> > there
>> > is 3 colours. Any help will be appreciated.
>> >

>>
>>
>>




 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      2nd Jul 2008
Not 3 colours, 3 conditions.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Alan" <(E-Mail Removed)> wrote in message
news:1C623B0C-3C63-4E04-8E88-(E-Mail Removed)...
> The reason it does not change the cell with the formula is because it is
> not
> the "target" cell, but is only affected by the "target" cell.
>
> I don't know what version you are running. I am running 2002. In 2002
> Conditional Formatting has all the Excel standard colors, not just 3.
>
> Format
> Conditional Formatting
> Click the Format button
> Click the Pattern tab.
> All Excel standard colors are available here.
>
> Conditional Formatting is the easiest way to go. You could calculate each
> cell in the range after a change occurs.
>
>
> Alan
>
>
>
> "Ram B" wrote:
>
>> I have added a VB script to a sheet to change color of the cell based on
>> input
>> Private Sub Worksheet_Change(ByVal Target As Range)
>> Dim icolor As Integer
>>
>> If Not Intersect(Target, Range("F1:F510")) Is Nothing Then
>> Select Case Target
>> Case "Red"
>> icolor = 3
>> Case "Green"
>> icolor = 4
>> Case "Blue"
>> icolor = 5
>> Case "White"
>> icolor = 2
>> Case "Gray"
>> icolor = 15
>> Case ""
>> icolor = 0
>> Case Else
>> 'Whatever
>> End Select
>>
>> Target.Interior.ColorIndex = icolor
>> Target.Font.ColorIndex = icolor
>>
>> End If
>>
>> End Sub
>> ---------------------------------------------------
>> This works well if the data is entered manually.
>> some cells that have a calculated input using a formula does not get
>> updated. It works if I use "Conditional Formatting" but the limitation
>> there
>> is 3 colours. Any help will be appreciated.
>>



 
Reply With Quote
 
Ram B
Guest
Posts: n/a
 
      2nd Jul 2008
Thanks Works like a charm

"Bob Phillips" wrote:

> Here you are
>
> Private Sub Worksheet_Calculate()
> Dim icolor1 As Long
> Dim icolor2 As Long
> Dim cell As Range
>
> For Each cell In Range("F1:F510")
>
> icolor1 = xlColorIndexNone
> icolor2 = xlColorIndexAutomatic
> Select Case cell.Value
> Case "Red": icolor1 = 3: icolor2 = 3
> Case "Green": icolor1 = 4: icolor2 = 4
> Case "Blue": icolor1 = 5: icolor2 = 5
> Case "White": icolor1 = 2: icolor2 = 2
> Case "Gray": icolor1 = 15: icolor2 = 15
> Case Else: 'Whatever
> End Select
>
> cell.Interior.ColorIndex = icolor1
> cell.Font.ColorIndex = icolor2
> Next cell
>
> End Sub
>
>
> --
> __________________________________
> HTH
>
> Bob
>
> "Ram B" <(E-Mail Removed)> wrote in message
> news:02ABD4B8-B833-45FF-8105-(E-Mail Removed)...
> >
> > I am engineer with little knowledge of VB. Would it be possible for you
> > to
> > help me with the code?
> > "Bob Phillips" wrote:
> >
> >> Use the calculate event and cycle through each cell in the range.
> >>
> >> --
> >> HTH
> >>
> >> Bob
> >>
> >> (there's no email, no snail mail, but somewhere should be gmail in my
> >> addy)
> >>
> >> "Ram B" <(E-Mail Removed)> wrote in message
> >> news:6717DF5B-3C5E-4383-AE8C-(E-Mail Removed)...
> >> >I have added a VB script to a sheet to change color of the cell based on
> >> >input
> >> > Private Sub Worksheet_Change(ByVal Target As Range)
> >> > Dim icolor As Integer
> >> >
> >> > If Not Intersect(Target, Range("F1:F510")) Is Nothing Then
> >> > Select Case Target
> >> > Case "Red"
> >> > icolor = 3
> >> > Case "Green"
> >> > icolor = 4
> >> > Case "Blue"
> >> > icolor = 5
> >> > Case "White"
> >> > icolor = 2
> >> > Case "Gray"
> >> > icolor = 15
> >> > Case ""
> >> > icolor = 0
> >> > Case Else
> >> > 'Whatever
> >> > End Select
> >> >
> >> > Target.Interior.ColorIndex = icolor
> >> > Target.Font.ColorIndex = icolor
> >> >
> >> > End If
> >> >
> >> > End Sub
> >> > ---------------------------------------------------
> >> > This works well if the data is entered manually.
> >> > some cells that have a calculated input using a formula does not get
> >> > updated. It works if I use "Conditional Formatting" but the limitation
> >> > there
> >> > is 3 colours. Any help will be appreciated.
> >> >
> >>
> >>
> >>

>
>
>
>

 
Reply With Quote
 
Alan
Guest
Posts: n/a
 
      2nd Jul 2008
Thanks Bob, I didn't catch that. I'll read closer next time.

Alan


"Bob Phillips" wrote:

> Not 3 colours, 3 conditions.
>
> --
> HTH
>
> Bob
>
> (there's no email, no snail mail, but somewhere should be gmail in my addy)
>
> "Alan" <(E-Mail Removed)> wrote in message
> news:1C623B0C-3C63-4E04-8E88-(E-Mail Removed)...
> > The reason it does not change the cell with the formula is because it is
> > not
> > the "target" cell, but is only affected by the "target" cell.
> >
> > I don't know what version you are running. I am running 2002. In 2002
> > Conditional Formatting has all the Excel standard colors, not just 3.
> >
> > Format
> > Conditional Formatting
> > Click the Format button
> > Click the Pattern tab.
> > All Excel standard colors are available here.
> >
> > Conditional Formatting is the easiest way to go. You could calculate each
> > cell in the range after a change occurs.
> >
> >
> > Alan
> >
> >
> >
> > "Ram B" wrote:
> >
> >> I have added a VB script to a sheet to change color of the cell based on
> >> input
> >> Private Sub Worksheet_Change(ByVal Target As Range)
> >> Dim icolor As Integer
> >>
> >> If Not Intersect(Target, Range("F1:F510")) Is Nothing Then
> >> Select Case Target
> >> Case "Red"
> >> icolor = 3
> >> Case "Green"
> >> icolor = 4
> >> Case "Blue"
> >> icolor = 5
> >> Case "White"
> >> icolor = 2
> >> Case "Gray"
> >> icolor = 15
> >> Case ""
> >> icolor = 0
> >> Case Else
> >> 'Whatever
> >> End Select
> >>
> >> Target.Interior.ColorIndex = icolor
> >> Target.Font.ColorIndex = icolor
> >>
> >> End If
> >>
> >> End Sub
> >> ---------------------------------------------------
> >> This works well if the data is entered manually.
> >> some cells that have a calculated input using a formula does not get
> >> updated. It works if I use "Conditional Formatting" but the limitation
> >> there
> >> is 3 colours. Any help will be appreciated.
> >>

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditional Formatting Does Not Refresh Automatically Steve Microsoft Excel Discussion 3 20th Jan 2010 04:16 PM
Conditional formatting in a table is lost on table refresh =?Utf-8?B?U3RldmUgSHVja2V0dA==?= Microsoft Excel Worksheet Functions 0 6th Nov 2007 11:39 AM
Conditional Formatting - Date Refresh =?Utf-8?B?S2FyYQ==?= Microsoft Excel Worksheet Functions 3 7th Jun 2007 09:56 PM
Conditional Formatting No Longer Conditional in 2007 Beta =?Utf-8?B?Q2FjdHVhci1Oby1KdXRzdQ==?= Microsoft Excel Crashes 0 17th Nov 2006 10:01 PM
Conditional Formatting that will display conditional data =?Utf-8?B?QnJhaW5GYXJ0?= Microsoft Excel Worksheet Functions 1 13th Sep 2005 05:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:52 PM.