VBA – Function to write the divisors of a number

Yesterday I wrote an article for an Excel function, checking whether a specified number is prime or not.

prime_numbers

Today I tought that it would be somehow a good idea to modify this function, in a way to check the number and if it is not prime to write down the divisors. Actually it was not very tough, as far as I have changed only a few lines of the code, making it a lot slower by removing the square root from the previous calculation. Anyway, the speed is not an issue, so enjoy the result from the routine “TestPrimeNumbers()” here:

ImmediateWindowFunction

The way the function works can be viewed here:

CheckingTheFunctions

And finally the code. Find the 10 differences with the one from yesterday :

Enjoy it! 🙂

Tagged with: , , ,