Solved

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

Posted on 2011-09-13
5
337 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
: Microsoft Office Collaborate for free and online versions of Microsoft  Word, Excel, Powerpoint, OneNote, Onedrive , Email, Calendar etc. In short we can say that Microsoft office is a suite of servers, applications and services developed by  Micr…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

628 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