+ Reply to Thread
Results 1 to 9 of 9

IF and MID

  1. #1
    Registered User
    Join Date
    02-13-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    13

    IF and MID

    Hi,

    I'm importing information from Outlook and one of the columns I need has the date. However, no matter how I format the column with the Date info, Outlook formats some of the dates as Mon 2/29. I'm trying to pull the date out, so I'm using the following formula

    =MID(C2,5,4)

    That is returning 2/29. However, the remainder of the dates in the column show up as (ie) 2/27/16.

    I'm looking for a formula that will just return the number of the month for the whole column. How do I add an IF statement that utilizes my MID statement?

  2. #2
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: IF and MID

    =MID(C2,5,4)+0

    The MID function returns a string ("2/29"). The +0 forces excel to look at it like a date. Format the cell as date.
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    02-13-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: IF and MID

    Hi,

    Your formula correctly formatted my date. However, as in the example below, the dates in COL A eventually is formatted correctly (ie) 2/27/16. When I enter your formula in COL B, it converts the correct date to what you see below...

    COL A COL B
    Mon 2/29 2/29/16
    Sun 2/28 2/28/16
    2/27/16 1/7/00

    If the date is formattted X/XX/XX, i want it to show the date as is. However, if is has (ie) Mon 2/29, I want the name of the date removed. I hope this makes more sense.

  4. #4
    Registered User
    Join Date
    02-13-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: IF and MID

    Ideally, it should look like this...

    Mon 2/29 2/29/16
    Sun 2/28 2/28/16
    2/27/16 2/27/16

  5. #5
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: IF and MID

    Ahhh, Is the value 2/27/16 (let's say that's in C9) showing as text or a number. To check, in a blank cell, put =ISNUMBER(C9) and see if it's true or false.
    If it's true, you can use this formula
    =IF(ISNUMBER(C2), C2, MID(C2,5,4)+0)
    If it's False, then
    =IF(DateValue(C2), DateValue(C2), Mid(C2,5,4)+0)

  6. #6
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: IF and MID

    Sorry, that will give an error if it's not a number

    try
    =IF(ISNUMBER(C2+0), DATEVALUE(C2), MID(C2,5,4)+0)

  7. #7
    Registered User
    Join Date
    02-13-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: IF and MID

    Thank you, that worked! How did you know to use that formula you recommended?

  8. #8
    Registered User
    Join Date
    02-13-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: IF and MID

    I went with this:

    =IF(ISNUMBER(C2),C2,MID(C2,5,4)+0)

    That formatted everything as X/XX/XX which is what I needed to remove the "Mon/Sun" issue and it left the remaining dates in its current format.

  9. #9
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: IF and MID

    How did you know to use that formula you recommended?
    I konw that if your cell formatting is not working, then the value being imported is not seen as a date (and all dates are numbers). The format m/d/yy is seen as a date by Excel so those values that were set up that way imported as numbers. So those we can leave alone.

    The others require a little manipulation to fix them. Thus we use the IF statement to determine the proper way to handle it.
    Hope that helps.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1