+ Reply to Thread
Results 1 to 9 of 9

"1" messing up prime no. module

  1. #1
    Registered User
    Join Date
    05-14-2008
    Location
    Southern Illinois
    MS-Off Ver
    2007
    Posts
    56

    "1" messing up prime no. module

    I don't know how to write modules yet, so I downloaded the one below. It checks to see if a number is a prime. It's cool and works, except any time that a 1 comes up. When I referrence a cell (B2 for example)that's value =1, with =isprime(B2), then I recieve "# value" as a result. This messes up the rest of my spreadsheet.




    Please Login or Register  to view this content.



    Can someone pleace help me with this?
    Last edited by VBA Noob; 12-28-2008 at 06:39 AM.

  2. #2
    Forum Contributor
    Join Date
    06-14-2008
    Posts
    153
    Hi,

    You are getting "#value" error because "1" is not a prime number.
    If you want to consider it as prime for any reason then change the following line in your code:
    Please Login or Register  to view this content.
    to this
    Please Login or Register  to view this content.
    Regards
    Welcome to: http://www.exceldigest.com/myblog/
    "Excel help for the rest of us"

  3. #3
    Registered User
    Join Date
    05-14-2008
    Location
    Southern Illinois
    MS-Off Ver
    2007
    Posts
    56
    Thanks for the responce.
    This module gives an answer as if its true or false.
    On all the other non prime numbers (other than one), it gives a false result, but not "# value" (as with the number one).
    On primes, it gives a true result.
    I need it to just treat ones like all other non primes.

  4. #4
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    173

    Please take a couple of minutes and read the Forum Rules - Rule 3

    As there is a 2hour time limit forediting threads I have wrapped your VBA code.

    Moderators can close/delete threads or ban users who continue to breach forum rules
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  5. #5
    Registered User
    Join Date
    05-14-2008
    Location
    Southern Illinois
    MS-Off Ver
    2007
    Posts
    56

    Thumbs up got you on the formating my question

    I now see what you mean by rule #3.
    I was trying to use the keyboard for the symbol "#".
    Anyone reading this, don't make the same mistake, it's the "#" symbol you can click on in the screen where you type you messages/questions.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    That function can be simplified and made faster:
    Please Login or Register  to view this content.
    You can also do this with a formula:

    =OR(A1 = {2,3}, AND(MOD(A1, ROW( INDIRECT("2:" & INT( SQRT(A1) ) ) ) ) <> 0) )
    Last edited by shg; 07-13-2008 at 03:29 PM. Reason: Extended limits of functionality

  7. #7
    Registered User
    Join Date
    05-14-2008
    Location
    Southern Illinois
    MS-Off Ver
    2007
    Posts
    56

    Talking Thanks shg

    I've been working on it also, and came up with:

    Please Login or Register  to view this content.
    This works with the module I've been using, but that module has definately been bogging down my proccessing time. I think I'll try the version you just provided me with. Hopefully I won't have to refresh three time before getting all the numbers to fill in now. Once again Excel forum has done it again. Thanks for all the help.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    I made some changes to the code in my prior post ...

  9. #9
    Registered User
    Join Date
    05-14-2008
    Location
    Southern Illinois
    MS-Off Ver
    2007
    Posts
    56
    Thanks
    SOLVED

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1