Project Euler #1-3 in VBA
While quickly running over your code, my eyes stopped on your function KeepDividingWhileInt.

It seemed over-complicated.

Let's write what it does:


Creates isDivisible
Sets isDivisible to true
Loops while isDividible is true:


If numToDivide Mod divisor is 0


Divides numToDivide by divisor

Else


Sets isDivisible to false


Returns numToDivide




Well, there is a subtle bug on step 2: You assume that the number is divisible by divisor, which may not be true (e.g.: KeepDividingWhileInt(3,2)).

Also, the whole code could be extremely simplified, by moving the condition inside that if into the while.

Also, you could try to use While ... Wend instead of Do While ... Loop, as suggested by @Mat's Mug. This point actually applies everywhere on your code.



The final result:

Public Function KeepDividingWhileInt(ByVal numToDivide As Long, ByVal divisor As Long) As Long

    While numToDivide Mod divisor = 0
        numToDivide = numToDivide / divisor
    Wend

    KeepDividingWhileInt = numToDivide

End Function


Oh my! The function is so simple that you can read it in a single sentence:


  Divide numToDivide by divisor while the reminder is 0, returning the final result.


So simple, right?