+ 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

    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

  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

    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.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    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.

  4. #4
    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

    Sure, let your COMPUTER do all the work. Lazy slug.


+ 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