Solved

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

Posted on 2011-09-13
5
304 Views
Last Modified: 2012-05-12
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'?
0
Comment
Question by:concretesailors
  • 2
  • 2
5 Comments
 
LVL 50

Accepted Solution

by:
barry houdini earned 500 total points
ID: 36532718
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
 
LVL 5

Expert Comment

by:slycoder
ID: 36532794
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

0
 
LVL 7

Author Comment

by:concretesailors
ID: 36532863
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
 
LVL 50

Expert Comment

by:barry houdini
ID: 36533037
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
 
LVL 7

Author Comment

by:concretesailors
ID: 36537683
AH!
Therefor "IF [validation test], THEN do this, ELSE do this"
Very nice, and thank you.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now