#1
|
|||
|
|||
Cell color based on cell value as compared to another cell va
I have a spreadsheet in which I enter daily closing stock prices. I want to be able to automatically have the cell fill with a color that indicates whether the current day's closing price is one of the following: 1. Higher than the previous day's closing price 2. Lower than the previous day's closing price 3. The same as the previous day's closing price I have attached part of the spreadsheet I use (and manually fill in the current day cell color based on closing price change from the previous day's closing price). There are days with no data - SAT, SUN, holiday that need to be accounted for so that the correct previous day is referenced. I appreciate the help. Thanks. |
#2
|
|||
|
|||
How about this? Notice on a holiday and/or on a weekend, you need to transfer the values from the day before in order to fulfill the desired conditional format for the next trading day. The font and fill are both grey.
You posted this thread in Excel Programming, but I don't see any reason why you need any VBA as you can achieve this thru CF. |
#3
|
|||
|
|||
I see what you mean by having the FRI value repeated on SAT and SUN so that no "special" handling would be required. I like that.
I am new to the forum so I apologize if I posted it in the incorrect place. I do not know how to accomplish my desired result using conditional formatting in this regard. That was really the main thrust of what I was asking help on. Thanks very much for your reply. That got me part of the way there. |
#4
|
|||
|
|||
A possible solution is in attached workbook.
Conditional formatting is defined for column B. I think you can apply the same logic for other columns too. The colors for conditional formatting are selected as near of yours as was possible from default ones in my color palette. Holidays list is a fake one - I added the one you had in your example. Edit: Weekday numbers in column E are calculated as ISO weekday numbers (European ones). With US weekday numbers the formulas in other columns will be much more complex, and this will affect workbooks performance when data amount increases. |
#5
|
|||
|
|||
Thanks for your reply.
I somewhat understand what you have done. What I don't get is the mechanics of how the cells in A5:A16 get the appropriate colors assigned. Can you please let me know how this step is done? Thank you. |
#6
|
|||
|
|||
I imagine you are speaking about the last post which seems overkill to me. Why create a column (column E) of formulas to do the conditional formatting when you can apply the condition directly to the cells.
Maybe looking at some tutorials will help... https://exceljet.net/conditional-for...-with-formulas https://www.contextures.com/xlCondFormat03.html https://www.ablebits.com/office-addi...matting-dates/ These are just a few tutorials pasted around the internet. We could retype these steps, but since they are already typed out and not exactly sure what you are understanding, there should help. |
#7
|
|||
|
|||
Quote:
I defined tHolidays as a Table (to make it dynamic). Conditional formatting doesn't recognize Tables, and it doesn't work with named ranges either. The number of calculated columns may be reduced, but I kept every step to make for OP easier to understand the logic. And the number of calculated columns is really moot, OP can hide them, and having several columns with simple formulas may be advantageous compared with one column with super-complex formula. Instead of OP, I'd define the table on data sheet as Table too. Currently I left it as it was originally, but this means whenever a new rows of data are added (or rows are removed), all range references must be edited in all formulas - which means a lot of unneeded work. (And all conditional formatting rules must be edited too, when OP wants to do all calculations there. And those calculations will get quite complex too with references to several ranges on different sheets for every condition.) With Table defined on data entry sheet and all formulas replaced with Table formulas, the whole workbook will be dynamic. But this means, that there mus be a column in data entry Table, which determines conditional formatting condition for every row. |
#8
|
|||
|
|||
Quote:
Activate a cell in column B with prices, and select from Menu Home>Conditional Formatting>Manage Rules. 5 rules (a rule for every color) are defined there. When you want to apply conditional formatting to columns C and D too, you need additional 2 calculated columns with previous workday values for those columns, and additional 5 conditional formatting rules for every of those columns. |
#9
|
|||
|
|||
Quote:
I defined a block of 3 numbers and assigned the named range MyNumbers to it. In those cells I typed in 1, 1, and 1. As an example, I used in CF >> =SUM(MyNumbers)=3 Works okay for me. |
#10
|
|||
|
|||
Thank you all. The videos online suggested were a great help. I finally got it!
This thread can now be marked closed. Thanks again. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
looking to change cell color by typing number into the cell | ibs | Word Tables | 1 | 11-22-2016 06:31 PM |
Entering a number in a cell causes it to fill with the color of a nearby cell | Bill Martz | Excel | 1 | 04-23-2015 07:57 PM |
Cell Background Color: Base it on Content of Cell? | tatihulot | Excel | 4 | 08-14-2013 03:24 PM |
How can I fill cell color starting from Cell D5 using Conditional formatting instead | Learner7 | Excel | 0 | 07-08-2010 05:50 AM |
How can I make a cell color RED under the Today's date cell? | Learner7 | Excel | 2 | 07-08-2010 12:52 AM |