Link to home
Start Free TrialLog in
Avatar of El Conquistador
El ConquistadorFlag for United States of America

asked on

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'?
ASKER CERTIFIED SOLUTION
Avatar of barry houdini
barry houdini
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.

Public Sub CheckDateAddTwoYears()
    Select Case UCase(Trim(Range("A1").Value))
        Case "POWEREDGE 2900"
            Range("C1").Value = DateAdd("yyyy", 2, Range("B1").Value)
    End Select
End Sub

Avatar of El Conquistador

ASKER

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?
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
AH!
Therefor "IF [validation test], THEN do this, ELSE do this"
Very nice, and thank you.