Solved

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

Posted on 2011-09-13
5
313 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
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 …

770 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