+ Reply to Thread
Results 1 to 9 of 9

Replace Function problem

  1. #1
    Forum Contributor
    Join Date
    04-11-2008
    Location
    Malaysia
    MS-Off Ver
    Office for Mac 2016
    Posts
    138

    Arrow Replace Function problem

    Hi guys again...Another small problem im face..hehe

    I have this set of number..

    987654.

    What im trying to do is this..I read this number and check for the first number with the 2nd number. If its greater then i will swap it. Im trying to do this so that my number can be rearranged as 456789.

    Please Login or Register  to view this content.
    As you see i tryied this code can replace the 2nd number to the first and i get 887654. How can i put 2 replace statements at the same time so that i can swap the 98 to 89...

    Kinda confused...Anyone care to help out..
    Last edited by newbie1234; 12-17-2008 at 12:23 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Please Login or Register  to view this content.
    =AnaSort("987654") returns "456789"
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492
    My take on it:
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Forum Contributor
    Join Date
    04-11-2008
    Location
    Malaysia
    MS-Off Ver
    Office for Mac 2016
    Posts
    138
    Quote Originally Posted by shg View Post
    Please Login or Register  to view this content.
    =AnaSort("987654") returns "456789"
    Hi sir.. How do i paste your code and where sir?

  5. #5
    Forum Contributor
    Join Date
    04-11-2008
    Location
    Malaysia
    MS-Off Ver
    Office for Mac 2016
    Posts
    138
    Quote Originally Posted by JBeaucaire View Post
    My take on it:
    Please Login or Register  to view this content.
    thanks..but kinda confused seeing your long code...

    Please Login or Register  to view this content.
    Could you explain to me how this works..? So that i can apply it on my own for the next set of numbers..

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492
    NUMBER = 123456

    =RIGHT(A1,1) would give you the last digit in cell A1. =6 (but we don't need that)
    =LEFT(A1,2) would give you the first TWO digit in the cell A1. =12

    Now for the fun, I want the last digit from the LEFT formula, so I snug them together:
    =RIGHT(LEFT(A1,2)) - result =2 (the second digit)

    Now I concatenate the original first digit after that:
    =RIGHT(LEFT(A1,2))&LEFT(A1,1) =21

    Then, I figure out how many numbers were left over using a LEN formula
    =LEN(A1)-2) ..the -2 is to remove the first two digits I've already calculated above. =4

    Now I know how many digits are left over, so I concatenate them on to the end with a RIGHT function:
    RIGHT(A1,LEN(A1)-2) ...which adds on like so:
    =RIGHT(LEFT(A1,2))&LEFT(A1,1)&RIGHT(A1,LEN(A1)-2) =213456

    Now, the only left to do was put your MID test back on as an opening IF test, if true, the formula we constructed, if false, an A1 tacked onto the end.
    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 12-17-2008 at 01:30 AM.

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492
    Personal preference, using the LEFT/RIGHT combo or RIGHT/LEFT combo trick to get a particular digit out of the middle of a string is easier for me to do than the MID formula, which I know is the preference of many others.

  8. #8
    Forum Contributor
    Join Date
    04-11-2008
    Location
    Malaysia
    MS-Off Ver
    Office for Mac 2016
    Posts
    138
    Thanks alot for your wonderful explanation...Im learning something new day by day on Excel..Its really interesting and it do amazing things..
    Last edited by shg; 12-18-2008 at 01:10 AM. Reason: deleted spurious quote

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    newbie, please don't quote whole posts. It just clutters the forum.

+ 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