us fr nl

VBA : Project Euler: Project Euler - Problem #1   nl

Options: Save as PDF | Save attached file | Toggle line numbers


Type: sub
Added By: Rembo
Short Description:
From their website: 

"What is Project Euler?

Project Euler is a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve. Although mathematics will help you arrive at elegant and efficient methods, the use of a computer and programming skills will be required to solve most problems.

The motivation for starting Project Euler, and its continuation, is to provide a platform for the inquiring mind to delve into unfamiliar areas and learn new concepts in a fun and recreational context."

After reading some of the solutions discussed in Dick's blog I thought it would be fun to post some solutions on this website as well. Rather than copying and pasting solutions of other people I will post my own solution. They may not be the most efficient solutions but they do the job. The challenge is of course to find your own solution, although the use of the internet is encouraged. Please see the Project Euler website for a full explanation.

If you find this challenging I encourage you to sign up (free) and see how far you get with programming your VBA solution.

The problem description is included with the code.
Added: Jan 31 2009 at 1:44 PM
Modified: Feb 5 2009 at 11:59 AM
Related URLs


Run the routine, the answer is printed in the debugging screen.


Formatted | Unformatted
  1. 'Euler Problem #1
  2. 'If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9.
  3. 'The sum of these multiples is 23.
  4. '
  5. 'Find the sum of all the multiples of 3 or 5 below 1000.
  8. Sub Euler_0001()
  9. Dim i As Long
  10. Dim iTotal As Long
  12. iTotal = 0
  13. For i = 1 To Int(999.99 / 3)
  14. iTotal = iTotal + (i * 3)
  15. Next i
  16. For i = 1 To Int(999.99 / 5)
  17. iTotal = iTotal + (i * 5)
  18. Next i
  19. For i = 1 To Int(999.99 / 15)
  20. iTotal = iTotal - (i * 15)
  21. Next i
  22. Debug.Print iTotal
  23. End Sub

User comments :

Add a new comment   Back to Top
Atom Feed
Contact | About This Application | Scriptorium Website