Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Color cell depending on it's previous value

I would like to make a cell changing color depending on a comparison between
its previous and current values.

Say I would like to start with green background for the cell whatever the
value is, then if the new (calculated or input) value of the same cell is
above the previous one the background stays green, but if the new value is
less that the previous then the background turns to red.

this is somehow a recursif conditional formatting, is this possible?

Many Thanks in advance.
Simo
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Color cell depending on it's previous value

If the value changed from 10 to 5 and then later to 7, would you want the
color to become red and then go back to green??
--
Gary''s Student - gsnu200820


"Simo" wrote:

I would like to make a cell changing color depending on a comparison between
its previous and current values.

Say I would like to start with green background for the cell whatever the
value is, then if the new (calculated or input) value of the same cell is
above the previous one the background stays green, but if the new value is
less that the previous then the background turns to red.

this is somehow a recursif conditional formatting, is this possible?

Many Thanks in advance.
Simo

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Color cell depending on it's previous value

Yes Absolutly. any idea how to do this?

"Gary''s Student" wrote:

If the value changed from 10 to 5 and then later to 7, would you want the
color to become red and then go back to green??
--
Gary''s Student - gsnu200820


"Simo" wrote:

I would like to make a cell changing color depending on a comparison between
its previous and current values.

Say I would like to start with green background for the cell whatever the
value is, then if the new (calculated or input) value of the same cell is
above the previous one the background stays green, but if the new value is
less that the previous then the background turns to red.

this is somehow a recursif conditional formatting, is this possible?

Many Thanks in advance.
Simo

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Color cell depending on it's previous value

It can easily be done with an Event macro. You would need a different macro
for a calculated cell as opposed to an input cell. Let's look at the input
case. We will use cell B9 as the sample. In the worksheet code area, put
the following macro:

Dim OldValue As Variant
Private Sub Worksheet_Change(ByVal Target As Range)
Set t = Target
Set b9 = Range("B9")
If Intersect(t, b9) Is Nothing Then Exit Sub
If IsEmpty(OldValue) Then
OldValue = b9.Value
Exit Sub
End If
Application.EnableEvents = False
If b9.Value < OldValue Then
b9.Interior.ColorIndex = 3
Else
b9.Interior.ColorIndex = 50
End If
OldValue = b9.Value
Application.EnableEvents = True
End Sub


Because it is worksheet code, it is very easy to install and use:

1. right-click the tab name near the bottom of the window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you save the workbook, the macro will be saved with it.

To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm

--
Gary''s Student - gsnu200820


"Simo" wrote:

Yes Absolutly. any idea how to do this?

"Gary''s Student" wrote:

If the value changed from 10 to 5 and then later to 7, would you want the
color to become red and then go back to green??
--
Gary''s Student - gsnu200820


"Simo" wrote:

I would like to make a cell changing color depending on a comparison between
its previous and current values.

Say I would like to start with green background for the cell whatever the
value is, then if the new (calculated or input) value of the same cell is
above the previous one the background stays green, but if the new value is
less that the previous then the background turns to red.

this is somehow a recursif conditional formatting, is this possible?

Many Thanks in advance.
Simo

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Color cell depending on it's previous value

Excellent, thank you Sir.

do you have an example with calculated cell.

I will look at the sites you mention later.

Best Regards
Simo

"Gary''s Student" wrote:

It can easily be done with an Event macro. You would need a different macro
for a calculated cell as opposed to an input cell. Let's look at the input
case. We will use cell B9 as the sample. In the worksheet code area, put
the following macro:

Dim OldValue As Variant
Private Sub Worksheet_Change(ByVal Target As Range)
Set t = Target
Set b9 = Range("B9")
If Intersect(t, b9) Is Nothing Then Exit Sub
If IsEmpty(OldValue) Then
OldValue = b9.Value
Exit Sub
End If
Application.EnableEvents = False
If b9.Value < OldValue Then
b9.Interior.ColorIndex = 3
Else
b9.Interior.ColorIndex = 50
End If
OldValue = b9.Value
Application.EnableEvents = True
End Sub


Because it is worksheet code, it is very easy to install and use:

1. right-click the tab name near the bottom of the window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you save the workbook, the macro will be saved with it.

To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm

--
Gary''s Student - gsnu200820


"Simo" wrote:

Yes Absolutly. any idea how to do this?

"Gary''s Student" wrote:

If the value changed from 10 to 5 and then later to 7, would you want the
color to become red and then go back to green??
--
Gary''s Student - gsnu200820


"Simo" wrote:

I would like to make a cell changing color depending on a comparison between
its previous and current values.

Say I would like to start with green background for the cell whatever the
value is, then if the new (calculated or input) value of the same cell is
above the previous one the background stays green, but if the new value is
less that the previous then the background turns to red.

this is somehow a recursif conditional formatting, is this possible?

Many Thanks in advance.
Simo

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
color after depending on 1st value in a cell pedy Excel Discussion (Misc queries) 1 July 3rd 09 11:29 PM
sum cells depending on color of cell Morten Excel Worksheet Functions 1 March 31st 09 02:22 PM
Tab Color Changes depending on value of a cell Thiago Excel Discussion (Misc queries) 1 September 10th 08 01:30 PM
Want add color to the cell depending on the value selected from th Tom Ogilvy Excel Programming 0 August 16th 05 07:11 PM
Sum depending on cell background color gwag17 Excel Programming 3 July 12th 04 02:24 PM


All times are GMT +1. The time now is 12:10 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"