+ Reply to Thread
Results 1 to 11 of 11
  1. #1
    Registered User
    Join Date
    01-04-2010
    Location
    Birmingham, UK
    MS-Off Ver
    Excel 2007
    Posts
    4

    Arrow Breaking up a number

    Hi,

    I have a question which is taxing my head.

    I have a number in one cell which is between 1 and 15 inclusive, and I want to break which ever number is chosen into the sum of 1,2,4 and 8, with each digit displayed in a separate cell. In the remainder cells if any are blank I would like 0 (zero) to be displayed

    e.g.

    15 ----> Cell 1 = 1, Cell 2 = 2, Cell 3 = 4, Cell 4 = 8

    or

    9 -----> Cell 1 = 1, Cell 2 = 0, Cell 3 = 0, Cell 4 = 8

    Using the numbers 1,2,4 and 8 there is only one way to sum each of the numbers 1-15 inclusive. The results of the 4 cells I'm using an if statement to display an "x" next to an option.

    Not to sure on the best way to do this, any ideas?

  2. #2
    Forum Moderator shg's Avatar
    Join Date
    06-21-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007
    Posts
    25,134

    Re: Breaking up a number

    Welcome to the forum.

    Please take a few minutes to read the forum rules, and then start a new thread in one of the question forums -- this isn't one.

    Thanks.
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    01-04-2010
    Location
    Birmingham, UK
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Breaking up a number

    Sorry, do you want me to repost, or can you move the thread?

    Rgds

  4. #4
    Forum Moderator shg's Avatar
    Join Date
    06-21-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007
    Posts
    25,134

    Re: Breaking up a number

    I can't move the thread (not a Mod), so can you repost in the Worksheet Functions forum?
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,379

    Re: Breaking up a number

    thread moved.

  6. #6
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,379

    Re: Breaking up a number

    It's not clear where the values are etc but if given use of XL2007 if you have say 1,2,4,8 listed in B1:E1 and the value of interest (eg 15 or 9 etc...) in A2 then

    EDIT: revised

    Code:
    B2: =B$1*LEFT(RIGHT(TEXT(DEC2BIN($A2),"0000"),COLUMNS($B2:B2)),1)
    copied to D2
    is that what you want ?
    Last edited by DonkeyOte; 01-04-2010 at 12:30 PM.

  7. #7
    Registered User
    Join Date
    01-04-2010
    Location
    Birmingham, UK
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Breaking up a number

    No sorry, not if I'm using it correctly.

    If I know the answer is 9, I would like to excel to produce the digits in seperate cells of the sum. i.e. I could put the answer "9" in A1 and excel would show A2 "1" B2 "0" C2 "0" D2 "8"

    or if "15" is put in A1 excel would show A2 "1" B2 "2" C2 "4" D2 "8"

    Does that make sense?

  8. #8
    Forum Moderator shg's Avatar
    Join Date
    06-21-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007
    Posts
    25,134

    Re: Breaking up a number

    It does, and DO's suggestion does that:
    Code:
           A- B C D E
       1      1 2 4 8
       2    0 0 0 0 0
       3    1 1 0 0 0
       4    2 0 2 0 0
       5    3 1 2 0 0
       6    4 0 0 4 0
       7    5 1 0 4 0
       8    6 0 2 4 0
       9    7 1 2 4 0
      10    8 0 0 0 8
      11    9 1 0 0 8
      12   10 0 2 0 8
      13   11 1 2 0 8
      14   12 0 0 4 8
      15   13 1 0 4 8
      16   14 0 2 4 8
      17   15 1 2 4 8
    And alternative, in B2 and copied across and down:

    =B$1 * MID(DEC2BIN($A2, 4), 5 - COLUMNS($B2:B2), 1)
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  9. #9
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,379

    Re: Breaking up a number

    If you need to generate the values without headers then if A1 holds 9

    Code:
    B1: =2^(COLUMNS($B1:B1)-1)*LEFT(RIGHT(TEXT(DEC2BIN($A1),"0000"),COLUMNS($B1:B1)))
    copied across to E1 (B1:E1 copied down as nec.)
    edit:

    or to use shg's more succinct version simply modify along same lines as above re: use of 2^ multiplier, ie:

    Code:
    B1: =2^(COLUMNS($B1:B1)-1)*MID(DEC2BIN($A1,4),5-COLUMNS($B1:B1),1)
    copied across to E1 (B1:E1 copied down as nec.)
    Last edited by DonkeyOte; 01-04-2010 at 12:46 PM.

  10. #10
    Forum Moderator daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2007
    Posts
    9,506

    Re: Breaking up a number

    You could avoid DEC2BIN with this version.....

    Number in A2 then this formula in B2 copied across as far as you need

    =(MOD($A2,2^COLUMNS($B2:B2))>=2^COLUMNS($B2:B2)/2)*(2^COLUMNS($B2:B2)/2)

  11. #11
    Registered User
    Join Date
    01-04-2010
    Location
    Birmingham, UK
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Breaking up a number

    Cheers, copied it wrong!! Works a treat! Many Thanks!!!

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.2.0