# Excel Add Two Years to Date String in Cell if Seperate Cell Contains String

I have an Excel spreadsheet in which I have several cells in one row pertaining to one server. One of these cells contains the type of server. E.g. A1 contains PowerEdge 2900. Cell B1 contains a date string in the format 06/14/2011. I need to do a validation formula to the extent that if A1 = 'PowerEdge 2900' then B1 = 06/14/13... adding two years to the date string in cell B1 in the above example..
Now the question, what is the formula for adding two years to B1 IF A1 contains the string 'PowerEdge 2900'?
LVL 7
###### Who is Participating?

x

Commented:
You can add two years to a date with EDATE function in Excel 2007, e.g. with date in A1

=EDATE(B1,24)

so to do that conditionally in C1 you could use this formula

=IF(A1="PowerEdge 2900",EDATE(B1,24),B1)

if you want to add different periods for different descriptions then some sort of lookup table would be better.....

regards, barry
0

Commented:
I would use a select case in a macro - but I agree, you should have a cell that indicates "original date" and have a "modified date" cell that reflects the change.

Select Case UCase(Trim(Range("A1").Value))
Case "POWEREDGE 2900"
End Select
End Sub

0

Author Commented:
OK, EDATE formula works great, and I appreciate the quick response, but what is that formula doing?

What this is is a Dell Warranty Spreadsheet for over 400 servers. Not all 400+ servers are PE2900, but we just updated the warranty on all PE2900s for two more years, across the board. So I appreciate the assistance, but so that I can learn, what is the formula doing?
0

Commented:
EDATE just adds months to a date so the 24 represents 24 months = 2 years. Within the IF function those 24 months are added if the condition is TRUE, i.e. if A1 is the correct text....otherwise the formula returns just the unchanged date B1....

regards, barry
0

Author Commented:
AH!
Therefor "IF [validation test], THEN do this, ELSE do this"
Very nice, and thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.