VBA – Function in Excel to check prime numbers

Prime Numbers Excel Function

Prime numbers are numbers, divisible by themselves. In the current example I simply made an Excel VBA function telling us whether a number is prime or not. It works as a charm šŸ™‚ CheckĀ the primeĀ numbers between 1 andĀ 100:

VBA Function

Check how the formula works in Excel:

Excel Function

So, this is how it works. And finally, here comes the code:

Prime Numbers Matrix and Coloring

Creating a matrix of the prime numbers and coloring the prime numbers in green is achieveable with some VBA code and taking care of the numbers a bit more. Building the “sieve” looks like this:

Once the “sieve” is built, then the isPrime boolean function can be introduced. The whole code, from a blank page looks like this:

Cheers! šŸ™‚

Tagged with: , , , , ,