+ Reply to Thread
Results 1 to 8 of 8

Noob: don't know how to write IF statements for =mid formula (simple code)

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-23-2015
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    187

    Noob: don't know how to write IF statements for =mid formula (simple code)

    Hi all,

    Sample Book.xlsx
    please refer to this sample workbook!


    I am currently using a report that gives me the field ex: “12/28/2014 - 1/10/2015 (Final Invoice)”. I am currently using logic in excel with the =mid formula to break up this line into two parts, start and end date. With that line broken up into two strings, excel doesnt recognize it as a date yet so I use =datevalue after which it works. I use logic in excel to break up the period into working days per month (worksheet G:R), so I can prorate things.

    The Problem:
    As of row 1979 the string becomes “1/11/2015 - 1/24/2015 (Final Invoice)” use contains fewer characters then the previous and my mid formula translate the End Date to “1/24/2015 (“ because of that bracket at the end the =datevalue function won’t work. I know I can go in and change the mid formula to start at character 12 instead of 13, or have length of 10 characters instead of 11 to fix this. But I cannot do on every report it’s too time consuming….

    I was thinking since =mid formula doesn't work, to use VBA code with IF statements if that line starts with a 1-9 (single digits) then get my mid formula to look at 12 characters instead of 13, and if its 10-12 (double digits) then look at 13 characters in my mid formula.....Does anyone know code to get this done. I would really appreciate it. any things help, i'm open to taking a different route if you see another way to do this.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,530

    Re: Noob: don't know how to write IF statements for =mid formula (simple code)

    For the first date: =MID(B6349,1,FIND(" ",B6349))
    For the second date: =SUBSTITUTE(TRIM(RIGHT(SUBSTITUTE(B6349," (Final Invoice)",""),FIND("-",B6349))),"- ","")
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Contributor
    Join Date
    09-23-2015
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    187

    Re: Noob: don't know how to write IF statements for =mid formula (simple code)

    Thank you John! this works too, turns out I don't need to use VBA anymore becasue of you guys ....does anyone know how to mark thread as SOLVED

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Noob: don't know how to write IF statements for =mid formula (simple code)

    Maybe? Left Right functions instead?

    
    Column C  =LEFT(B2,9)
    
    Column D  =LEFT(RIGHT(B2,25),10)
    Last edited by JOHN H. DAVIS; 10-19-2015 at 11:43 AM.

  5. #5
    Forum Contributor
    Join Date
    09-23-2015
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    187

    Re: Noob: don't know how to write IF statements for =mid formula (simple code)

    This works and is great. Thank you Ali!

  6. #6
    Registered User
    Join Date
    10-10-2015
    Location
    Hoboken, Antwerp, Belgium
    MS-Off Ver
    2010
    Posts
    93

    Re: Noob: don't know how to write IF statements for =mid formula (simple code)

    Hi,
    What if you add a column and first get rid of this part of the string "(Final Invoice)"?
    You can use this function for it:
    Formula: copy to clipboard
    =Left(cell,find.spec(" (";cell))

    Then you can use this formula to get the left part of the rest of the string:
    Formula: copy to clipboard
    = left(new string,find.spec(" - ";new string))

    And this formula to get the right part of the new string
    Formula: copy to clipboard
    = right(new string, find.spec(" - "; new string))
    Greetings,

    Cheetahke

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,530

    Re: Noob: don't know how to write IF statements for =mid formula (simple code)

    You are welcome, lougs7!

  8. #8
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Noob: don't know how to write IF statements for =mid formula (simple code)

    You're welcome. Glad to help out. Note my edit to my post.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Simple macro repetition, I am a total noob
    By chart23 in forum Excel Programming / VBA / Macros
    Replies: 23
    Last Post: 10-16-2014, 01:16 PM
  2. [SOLVED] Code to evaluate contents of one cell then write new values into new cell (Simple IF Stmt)
    By clemsoncooz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-05-2012, 11:54 AM
  3. [SOLVED] using code variable to write cell formula
    By rpw in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-05-2006, 02:00 PM
  4. [SOLVED] Write formula with code ...
    By Sige in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 02-06-2006, 03:25 PM
  5. [SOLVED] I need a simple macro but im a noob.
    By flyboy0204 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-21-2006, 12:25 AM
  6. How to write an average formula from VBA- SHOULD BE SIMPLE!
    By cantonarv in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-11-2005, 10:05 AM

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