How to make a cell turn red if the value is a prime number

popcornrulez

New Member
Joined
Mar 15, 2013
Messages
35
I know how to do the Conditional Formatting stuff for cells, but I need to make a cell that turns red if the number is a prime number. I just need to know if there is a formula that returns true if the value is a prime number and false if it isn't. And if you guys know of an add-in for excel that has a similar formula please post the link.


popcornrulez
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
CF formula (if cell is A1):
=OR(A1=2,A1=3,ISNA(MATCH(TRUE,A1/ROW(INDIRECT("2:"&INT(SQRT(A1))))=INT(A1/ROW(INDIRECT("2:"&INT(SQRT(A1))))),0)))
 
Upvote 0
CF formula (if cell is A1):
=OR(A1=2,A1=3,ISNA(MATCH(TRUE,A1/ROW(INDIRECT("2:"&INT(SQRT(A1))))=INT(A1/ROW(INDIRECT("2:"&INT(SQRT(A1))))),0)))

I need to be able to implement the formula into a conditional formatting rule, and I tried this formula and it said true on 7, (which is right), and true on 9 also, (which isn't right).
 
Upvote 0
It works exactly right as is in a CF formula, but as a worksheet formula it must be array-entered (Ctrl+Shift+Enter). it shows FALSE for 9 if done as I said.
 
Upvote 0

Forum statistics

Threads
1,213,534
Messages
6,114,186
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top