+ Reply to Thread
Results 1 to 11 of 11

Excel 2007 : How to append zeroes and extract middle digits

Hybrid View

  1. #1
    Registered User
    Join Date
    12-27-2010
    Location
    Philippines
    MS-Off Ver
    Excel 2007
    Posts
    24

    Unhappy How to append zeroes and extract middle digits

    I'm supposed to generate random numbers using the mid square method. Initially, I have a 4-digit number which I'm supposed to square. Then I have to extract the middle digits.I square this again and extract the middle digits. The problem is, I don't always get 8 digits when I square it. I'm supposed to append zeroes to the left of the string to make it exactly 8 digits, but I don't know how to do it.

    example:

    8065 65044225
    0442 195364
    5364 28772496

    As you can see, I'm supposed to get 1953 instead of 5364. I really don't know what to do, please help. thanks!
    Last edited by whattodo; 12-29-2010 at 06:18 AM.

  2. #2
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: How to append zeroes and extract middle digits

    Hi and welcome to the board supposing the first number squared is in B1, in A2 enter

    to extract the numbers, use
    =mid(text(b1,"00000000"),3,4)
    that you can then square in b2, etc..

  3. #3
    Registered User
    Join Date
    12-27-2010
    Location
    Philippines
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: How to append zeroes and extract middle digits

    It works perfectly! thank you so much!

  4. #4
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: How to append zeroes and extract middle digits

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

  5. #5
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: How to append zeroes and extract middle digits

    With 8065 in A2

    In B2
    =A2^2
    Drag/Fill Down

    In A3
    =MID(TEXT(B2,"00000000"),3,4)
    Drag/Fill Down

    You could format Column A > Custom "0000" and Column B >Custom "00000000", if you want

    The formula in one step might be
    In B2
    =MID(TEXT(MID(TEXT(A2^2,"00000000"),3,4)^2,"00000000"),3,4)^2

    Hope this helps

    [EDIT]
    Browser slow in refreshing yet again.
    Last edited by Marcol; 12-27-2010 at 08:00 AM.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  6. #6
    Valued Forum Contributor squiggler47's Avatar
    Join Date
    02-17-2009
    Location
    Littleborough, UK
    MS-Off Ver
    Excel 3.0 to 2007+2010! (couldnt get 2.1 working)
    Posts
    1,013

    Re: How to append zeroes and extract middle digits

    @marcol

    =MID(RIGHT(rept(0,8)&(B1^2),8),3,4)

    would be ok for doing it in 1 step!

    The answer should be 4 digits rather than 8!
    using the formula above, allows for different lengths :-

    =MID(RIGHT(rept(0,a1*2)&(B1^2),a1*2),a1/2+1,a1)

    Where A1 is the number of digits required in the random number! (note 2,4,6 are valid values)
    Regards
    Darren

    Update 12-Nov-2010 Still job hunting!

    If you are happy with the results, please add to our reputation by clicking the blue scales icon in the blue bar of the post.

    Learn something new each day, Embrace change do not fear it, evolve and do not become extinct!


  7. #7
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: How to append zeroes and extract middle digits

    @ squiggler
    Indeed it might, depends on your interpretation of "one step"

    8065 returns 03814209 was my reading of the problem.

  8. #8
    Valued Forum Contributor squiggler47's Avatar
    Join Date
    02-17-2009
    Location
    Littleborough, UK
    MS-Off Ver
    Excel 3.0 to 2007+2010! (couldnt get 2.1 working)
    Posts
    1,013

    Re: How to append zeroes and extract middle digits

    8065 returns 03814209 was my reading of the problem.

    yes but the point was to return 8 digits, so that the middle 4 could be returned for the next line as its a repeated sequence!

    So in this case 8065 would return 03814209 leading to 8142 to be the seed for the next line!

    the fun starts after a few iterations it could hit a few of the values that make it loop indefinately between a few values!

    Or hit a value that shrinks to zero!
    Last edited by squiggler47; 12-27-2010 at 08:57 AM.

  9. #9
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: How to append zeroes and extract middle digits

    @ squiggler
    At the risk of appearing dumb, where's the problem with this?
    What can you see that that I'm missing?

    The OP seems happy with Post#2
    Attached Files Attached Files

  10. #10
    Valued Forum Contributor squiggler47's Avatar
    Join Date
    02-17-2009
    Location
    Littleborough, UK
    MS-Off Ver
    Excel 3.0 to 2007+2010! (couldnt get 2.1 working)
    Posts
    1,013

    Re: How to append zeroes and extract middle digits

    I assumed without checking that the 2 text statements where returning 8 digits, I couldn't see a need to have the 2 text statements otherwise, hence my reply!

  11. #11
    Registered User
    Join Date
    12-27-2010
    Location
    Philippines
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: How to append zeroes and extract middle digits

    thank you soooo much! i really appreciate all the help.

+ 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