+ Reply to Thread
Results 1 to 12 of 12

MID function not working properly

Hybrid View

  1. #1
    Registered User
    Join Date
    04-01-2017
    Location
    Mex
    MS-Off Ver
    365
    Posts
    4

    MID function not working properly

    So I created a concat formula to return column names all the way to "ZZ"; however, it's returning incorrect values for the second letter after "ai" and I can't seem to figure out why. The piece of formula misbehaving is the following (it has been simplified for convenience, but it works the same... or rather doesn't):

    =(MID("abcdefghijklmnopqrstuvwxyz",(38/26-(QUOTIENT(38-1,26)))*26,1))

    The result of start_num's argument is, of course, 12 (the 38 is AL's column number); HOWEVER, the letter given by MID is actually "k" (11th character), not "l", and short of actually sticking a "12" there, I haven't been able to make it work.


    This is one of those "optimization" experiments that ends up taking so much more time than just doing everything the "slow and inconvenient way"...
    Attached Files Attached Files
    Last edited by squashedmos; 12-28-2020 at 04:33 AM.

  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. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,658

    Re: MID function not working properly

    Welcome to the forum.

    There are instructions at the top of the page explaining how to attach your sample workbook.

    Are you still using Excel 2007? If not, please update your forum profile.
    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
    Registered User
    Join Date
    12-04-2020
    Location
    Bangkok
    MS-Off Ver
    365
    Posts
    61

    Re: MID function not working properly

    As Mod said, kindly attached an excel file, so that we can help you.

    In the meantime, is this what you're trying to do?

    =MID("abcdefghijklmnopqrstuvwxyz",MOD(38-1,26)+1,1)

  4. #4
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: MID function not working properly

    Your "Starting point" number does indeed return 12. EXACT also shows that it is indeed 12. However, this fixes it:

    =(MID("abcdefghijklmnopqrstuvwxyz",TRUNC((38/26-(QUOTIENT(38-1,26)))*26),1))

    suggesting that it does have "something" to do with Excel's floating point arithmetic...
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

  5. #5
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: MID function not working properly

    TRUNC helps, but it treats symptoms rather than causes.

  6. #6
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: MID function not working properly

    Welcome to the world of limited precision binary arithmetic.

    Note that (n/26-QUOTIENT(n-1,26))*26 = n-26*QUOTIENT(n-1,26). The latter is slightly more likely to produce an integer than the former, but neither are guaranteed to do so due to finite precision. What do I mean by finite precision. 0.3333 is 1/3 as a decimal fraction with ONLY 4 places to the right of the decimal point, but 3 times that is 0.9999 rather than 1.0. The same thing can happen in computers when dividing by anything other than powers of 2.

    That said, you actually want MOD(n-1,26)+1, which will always return an integer when n is an integer representing a column number.

    As a general rule, there's never a good time to use QUOTIENT in Excel unless you want that quotient as the FINAL result. As an intermediate term in more involved calculations, it's invariably the wrong thing to use.

  7. #7
    Registered User
    Join Date
    04-01-2017
    Location
    Mex
    MS-Off Ver
    365
    Posts
    4

    Re: MID function not working properly

    Thank you, hrlngrv, I'll keep that in mind for future functions I might need, it's a valuable insight I didn't know.

  8. #8
    Registered User
    Join Date
    04-01-2017
    Location
    Mex
    MS-Off Ver
    365
    Posts
    4

    Re: MID function not working properly

    AliGW, yes, sorry for not updating my info, it had been years since I had used my account, my bad.

    phatdear, thank you for your reply, I think your approach would have been simplest one, though I would've had to think of a workaround for columns with a "z" as second letter, but it does seem to work. Unfortunately, I didn't think of it before, perhaps in the future!

    Glenn, thank you for your reply. Indeed it does seem this one is on MS and not me, for a change, and your suggestion fixes everything without needing to rewrite anything much, perhaps it'll be what I implement, thank you very much.

  9. #9
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: MID function not working properly

    If what you are trying to do is return a series of incrementing column names, this:

    =LEFT(ADDRESS(1,COLUMNS($A:A),4),LEN(ADDRESS(1,COLUMNS($A:A),4))-1)

    dragged across works well.

  10. #10
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,651

    Re: MID function not working properly

    I wonder if i missed something, but

    with 2 indicates starting point is "b" (1 is "a", 2 is "b", 3 is "c",...)

    and there are 2 skipping columns between 2 cells

    try in first cell then drag accross:

    =LEFT(LOWER(ADDRESS(1,(COLUMNS($A:A)-1)*3+2,4)),LEN(ADDRESS(1,(COLUMNS($A:A)-1)*3+2,4))-1)
    Attached Files Attached Files
    Quang PT

  11. #11
    Registered User
    Join Date
    04-01-2017
    Location
    Mex
    MS-Off Ver
    365
    Posts
    4

    Re: MID function not working properly

    Glenn, bebo, it seems this would be a most elegant solution indeed, without need of workarounds of any sort, as far as I can tell. Thank you both.

  12. #12
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: MID function not working properly

    You're welcome.



    If that takes care of your original question, please select "Thread Tools" from the menu link above and mark this thread as SOLVED.

    It would also be very nice if you were to just click the Add Reputation button at the foot of any of the posts of members who helped you reach a solution.

+ 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. =COUNTA function not working properly
    By Stona in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-22-2020, 11:19 AM
  2. IF OR AND Function not working properly
    By cbrazeau in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-24-2020, 10:06 AM
  3. [SOLVED] IF Function Not working properly
    By kgtrader in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 05-31-2020, 07:52 AM
  4. [SOLVED] IndexMatch function not working properly
    By bubai in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-08-2015, 06:04 AM
  5. [SOLVED] Max Function Not Working Properly
    By STU22 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-25-2015, 07:41 PM
  6. Sums function not working properly...
    By Edrodriguez in forum Office 365
    Replies: 2
    Last Post: 05-18-2015, 09:59 AM
  7. Day Function Not Working Properly
    By clh7837 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-10-2014, 12:51 PM

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