Solved

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

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

757 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

18 Experts available now in Live!

Get 1:1 Help Now