Change cell color when date is older than one year - vba

I made a Userform where i can enter my data like product ID, place,.., in the Column „G“ i have the Date(e.g.20.4.2005)(Range is from G2 to G100) - i have bought something. When the typed Date is longer than one year the cellcolor should be turned to red, can somebody help me please?

Using Conditional formating is much better. It work on realtime, right after a cell's value is update. Here's the operation:
Select range G2 to G100
Select tab Home -> Conditional formating -> New rule
"Select rule type" selectbox: Format only cell that contain
Set condition for "Edit the rule Description": Cell Value -> Greater than -> Input the date you wanna compare
Click button Format -> Fill -> Select background colour that you wish
Click OK, OK

Related

Excel 2016: Conditional Formatting: Highlight row if cell value is in list

Excel 2016 Conditional Formatting question:
I have two tabs, Data and List:
Data has 5 columns. Column A is the item ID number, the others have
project related data.
List has 1 column. This is a list of ID numbers
that have been processed.
Here is the question:
How do I highlight the rows for processed ID numbers? I want to be able to add ID numbers to List as I process more rows. I want to see processed items in Data in green highlight, because green makes the boss happy!
Looking forward to your input!
I would use a VLOOKUP to find the value in the List sheet. An error means the value doesn't exist. Since you want to know if it does exist, just invert the boolean result with NOT
=NOT(ISERROR(VLOOKUP($A1,List!$A:$A,1,FALSE)))
Note: This is a Classic > Formula formatting rule, and the lookup value is $A1 because my "applies to" range starts on row 1 (and we always look at col A).
Rule:
Formatting Range:
Result:

Conditional formatting to show date task completed is in/out of target with icons

apologies for asking a basic question.
If cell A2 contains the dates a task should be completed by, and cell B2 contains the actual date completed.
Can the icons be used to show a green tick next to the date (in B2) if it is = or < A2 or a Red Cross if it's > than A2?
Many thanks
IMO not exactly a 'basic' Q. One solution, that does not use icon sets but attempts to mimic them, is to place in C1 and copy down to suit:
=IF(AND(A1<>"",B1<A1),CHAR(252),IF(A1<>"",CHAR(251),""))
then clear any existing CF, select ColumnC, choose Windings as font and HOME > Styles - Conditional Formatting, New Rule..., Use a formula to determine which cells to format and Format values where this formula is true::
=C1=CHAR(251)
Format..., select red font OK, OK.

Conditional Formatting (If/when)

Ok so I want a row to highlight red when the date in cell C1 is more than the cell in B1, but only if this is a difference of two months or less. I am sorry, I don't know how to embed a dummy spreadsheet. So for example, if B1 (clinic appointment due date) is Sep-17 and C1 (physical checks due date) is Oct-17, I want this row to highlight. If C1 is Dec-17, I don't want the row to highlight because this is more than two months from Sep-17.
Edited based on your new description, using Column A to represent Clinic Appointment Date and Column B to represent Physical Checks Due Date.
Use a rule based on DAYS().
Click on cell A1
Choose New rule from the Conditional Formatting menu.
Choose Use a formula to determine which cells to format
In Format values where this formula is true:, use the below formula:
=DAYS(B1, A1) < 60
Set up the formatting you want to use to highlight the cells. In the image below, I've set the ones that meet your requirements for highlighting to appear in red, and applied it to the first two rows in Column A (A1 and A2):
Here's the sheet with sample data in two rows, showing the conditional formatting working as requested:

Conditional Formatting or Macro Enabled - Change cell background color based on another cell value

I have a workstation inventory list that has a purchase date in cell "D" in which I have cell "I2" with =TODAY(). Cell "E" has a formula of =ROUND(YEARFRAC(D3,$I$2),0) to get the # of years value in Cell "E".
My question is regarding cell "F" I'd like for the cell to automatically change color based on the numbers of years in cell "E", but I'm struggling to do so. With either conditional formatting or finding a good macro to do so.
I have attached a screenshot to give you folks a better idea. I might've missed a similar thread while doing my research, but if anyone knows where I could look. That's a good answer for me.
You can use the regular conditional formatting:
Select "Use a formula to determine which cells to format" , set the rule like in the screen-shot below (if Years >= 1 and Years <=3).
Apply this formula to your entire range (don't forget to remove the $ sign before the row number so it will change with the rows numbers).
Repeat this step by adding 2 more rules for the other scenarios (same type by using a formula):
(if Years > 3 and Years <=4) then Yellow.
(if Years > 5) then Red. In your post you wrote: (Years > 5) in your legend in the right, but in your requested screen-shot you actually want to display if (Years >= 5) then Red. so you need to decide which one you want.
Select ColumnF and HOME > Styles - Conditional Formatting, New Rule..., Use a formula to determine which cells to format and Format values where this formula is true::
=AND(ROW()>2,E1>4,E1<>"")
Format..., select red Fill, OK, OK.
Then add a new rule of:
=AND(ROW()>2,E1<5,E1<>"")
with yellow fill and finally a third rule (though you could choose to apply a 'standard' fill instead) of:
=AND(ROW()>2,E1<4,E1<>"")
with the rather strange colour fill.
[1] If not added in the above order they should be rearranged in the Conditional Formatting Rules Manager window with red at the bottom and yellow in the middle.
[2] Check Stop if True for all three rules (or at least the top two).
[3] 0 is covered within the same rule as 1 to 3 years.
[4] To simplify range selection and updating all rules apply to the entire column. This though has complicated avoiding applying the formatting to the first two rows and any that are blank in ColumnE.
Try below conditions, it worked for me. You need to apply three different rules on same range
=$K$5>=5 - Red
=AND($K$5<5,$K$5>3) -Yellow
=AND($K$5>=1,$K$5<=3) - Green
I tend to limit conditional formatting to cases where I use them for a quite small and FIXED (never to be changed/added/deleted/moved) number of cells
Otherwise in the medium/long run it can both result in a worksheet mess (after copying&pasting and/or inserting/deleting cells) and size increase
That's why for the colouring of cells down a list I'd always use a VBA approach, like the following code:
Option Explicit
Public Sub main()
Dim cell As Range
Dim firstColor As Long, secondColor As Long, thirdColor As Long
With Worksheets("Inventory") '<--| change "Inventory" to your actual sheet name
firstColor = .Range("I9").Interior.Color '<--| change "I9" to your actual cell address with "1st color"
secondColor = .Range("I10").Interior.Color '<--| change "I10" to your actual cell address with "2nd color"
thirdColor = .Range("I11").Interior.Color '<--| change "I11" to your actual cell address with "3rd color"
For Each cell In .Range("E3", .Cells(.Rows.Count, "E").End(xlUp)).SpecialCells(XlCellType.xlCellTypeFormulas, xlNumbers) '<--| loop through column "E" from row 3 down to last non empty row cells with numbers deriving from formulas only
cell.Offset(, 1).Interior.Color = Switch(cell.value <= 3, firstColor, cell.value <= 4, secondColor, cell.value > 4, thirdColor) '<--| adjust current cell adjacent one color according to current cell value
Next cell
End With
End Sub
Note: I adjusted Switch() function conditions to match your example column "E" and "F" result, which is slightly different from what would come out of your "NO. Of Years" range legenda. Also, this latter has its first two ranges overlapping each other

How to fill cells based on complicated formula?

I have a complicated formula. What I'm looking to do is to set it up where if column A is YR then column B-J will highlight red if the date is more than 2 years ago and yellow if the date is within 30 days of reaching the 2 year mark.
If column A is P1, P2, P3, P4, or P5 then column B-J will highlight red if the date is more than 1 year ago and yellow if its within 30 days of reaching the one year mark.
You will want to create two conditional formatting rules. First select B2:J6 (as laid out in the image below, the bottom row will vary with your own data) with B2 as the Active Cell. Create a new formula using the Use a formula to determine which cells to format and supply the following for Format values where this formula is true:
=AND(OR($A2="P1",$A2="P2",$A2="P3",$A2="P4",$A2="P5",$A2="YR"),B2<=EDATE(TODAY(),(1+($A2="YR"))*-12))
Click Format and supply a red Fill. I also added a white Font for readability. Click OK to accept the format and then OK again to create the new rule.
With B2:J6 still selected, repeat with the following formula for a yellow fill.
=AND(OR($A2="P1",$A2="P2",$A2="P3",$A2="P4",$A2="P5",$A2="YR"),B2>EDATE(TODAY(),(1+($A2="YR"))*-12),B2<=(EDATE(TODAY(),(1+($A2="YR"))*-12)+30))
You results should be similar to the following.