+ Reply to Thread
Results 1 to 8 of 8

5 digit numbers where the sum is equal to 18

Hybrid View

  1. #1
    Registered User
    Join Date
    01-19-2011
    Location
    USA
    MS-Off Ver
    2000
    Posts
    2

    5 digit numbers where the sum is equal to 18

    It has been a while since I've worked with Excel, but I'm trying to find a way to see all five digit numbers where the sum of the digits is equal to 18? I want to see all combinations. Zeros should be included. I'm hoping if someone can get me started again, the neurons will start firing and I'll be able to pick up where I left off (many years ago). Thanks!

  2. #2
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: 5 digit numbers where the sum is equal to 18

    MomMel,

    Welcome to the Excel Forum.


    To get the most precise answer, it is best to upload/attach a sample workbook (sensitive data scrubbed/removed) that contains an example of your raw data on one worksheet, and on another worksheet your desired results.

    The structure and data types of the sample workbook must exactly duplicate the real workbook. Include a clear and explicit explanation of your requirements.

    To attach your workbook, scroll down and click on the Go Advanced button, then scroll down and click on the Manage Attachments button.
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: 5 digit numbers where the sum is equal to 18

    Welcome to the forum.

    You could list the numbers 99 to 99000 (this is an Excel 2007+ exercise) down a column starting in A2 . In the B2 and copy down,

    =SUM(--MID(A2, ROW(INDIRECT("1:" & LEN(A2))), 1))

    ... confirmed with Ctrl+Shift+Enter

    In C2 and down

    =A2=18

    AutoFilter col C for FALSE, clear those cells, unAutoFilter, and sort by col A:

           -A- -B- -C--
       1   Num Sum 18? 
       2    99  18 TRUE
       3   189  18 TRUE
       4   198  18 TRUE
       5   279  18 TRUE
       6   288  18 TRUE
       7   297  18 TRUE
       8   369  18 TRUE
       9   378  18 TRUE
      10   387  18 TRUE
      11   396  18 TRUE
      12   459  18 TRUE
      13   468  18 TRUE
      14   477  18 TRUE
      15   486  18 TRUE
      16   495  18 TRUE
    There are 3915 numbers left in the list.
    Last edited by shg; 01-19-2011 at 10:58 AM.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    01-19-2011
    Location
    USA
    MS-Off Ver
    2000
    Posts
    2

    Re: 5 digit numbers where the sum is equal to 18

    Thanks so much! This is perfect!
    Last edited by shg; 01-19-2011 at 11:09 AM. Reason: deleted spurious quote

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: 5 digit numbers where the sum is equal to 18

    Actually, errata and improvements.

    You can list the numbers 99 to 99000 stepping by 9: 99, 108, 117, ...

    Then autofilter, and 4840 numbers survive (I was doing this in Excel 2003, so couldn't list all the numbers stepping by one).

    Please don't quote whole posts.

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,971

    Re: 5 digit numbers where the sum is equal to 18

    Brute force approach:
    
    Sub List18s()
       Dim a As Long, b As Long, c As Long, d As Long, e As Long
       Dim lngCount As Long
       Dim varOut()
       ReDim varOut(1 To 99000)
       For a = 0 To 9
          For b = 0 To 9
             For c = 0 To 9
                For d = 0 To 9
                   For e = 0 To 9
                      If a + b + c + d + e = 18 Then
                         lngCount = lngCount + 1
                         varOut(lngCount) = CLng(a & b & c & d & e)
                      End If
                   Next e
                Next d
             Next c
          Next b
       Next a
       ReDim Preserve varOut(1 To lngCount)
       Range("A1").Resize(lngCount).Value = Application.Transpose(varOut)
    End Sub
    Everyone who confuses correlation and causation ends up dead.

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,971

    Re: 5 digit numbers where the sum is equal to 18

    When I figure out how to get my computer to answer questions here, then maybe I'll start doing the work again.

+ 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