Numbers are cool and fun to play with in my opinion, especially Prime Numbers. I wrote about this some time ago in a post HERE and I've had some ideas since then. In that post I was using a Excel spread sheet with some Visual Basic code to create a number sequence then I was using another function to check if a number in a particular cell was prime. The function was scanning through a list of prime numbers in the spreadsheet and if it found a match the formatting for the cell that matches was changed to blue using Copy Formats in Excel 2007 instead of the Conditional Formatting idea. To do all that in Visual Basic for Excel was fun but overly complicated as pointed out to me by Codemann8. He commented on that last post and left a formula for Excel that can check to see if a number is prime! It's a cryptic and really cool formula that he didn't take credit for (it's out on the web) but it will check for prime numbers. I finally got around to trying this formula out and I used it to highlight prime numbers in a simple multiplication chart that uses modulo arithmetic. Below is what the Multiplication Modulo Chart looked like but I also want to show how to set this formula up to control Conditional Formatting in Excel 2007 because it took me awhile to get it to work.
 |
Excel 2007 Conditional Formatting in Modulo Multiplication Table |
The above picture shows what the spreadsheet ended up looking like. Along the top and down the left side are the numbers 1-257 (only 1-23 are shown) and in the middle are the products of those numbers - a multiplication chart. In the upper left corner in the highlighted cell is the modulus of multiplication. In other words the numbers in the top and left are being multiplied modulo 23 in this case. The blue cells are the prime numbers being highlighted by the formula below using the Conditional Formatting function. At the end of this post I made a short video that cycles the multiplication chart through various number sequences showing the various patterns the prime numbers make! Really Cool!!!
Below is the formula that Codemann8 left in a comment on another post I wrote and it checks to see if a number is prime returning the Excel TRUE condition if it is. If you 'Google' that formula you will get a bunch of pages that talk about it. Whoever came up with this formula had their thinking cap on! =OR(A1=2,A1=3,ISNA(MATCH(TRUE,A1/ROW(INDIRECT("2:"&INT(SQRT(A1))))=INT(A1/ROW(INDIRECT("2:"&INT(SQRT(A1))))),0)))
Click below to read more about how to set up Conditional Formatting in Excel 2007 to use this formula and to see the boring exciting video I made of the spreadsheet cycling through various number sequences, highlighting the prime numbers as it goes!