Results 1 to 9 of 9

"1" messing up prime no. module

Threaded View

  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.




    Function IsPrime(ByRef rngVal As Range) As Variant
    Dim ValPrime As Boolean
    Dim x As Long
    Dim ValGCD As Double
    Dim Val As Double
    
    Val = rngVal.Value
    
    If Val = 1 Or Val < 0 Or Val <> Int(Val) Or IsEmpty(rngVal) = True Then
    IsPrime = "#VALUE"
    Exit Function
    End If
    
    ValPrime = True
    
    For x = 2 To Val - 1
    If Val / x = Int(Val / x) Then
    ValPrime = False
    IsPrime = ValPrime
    Exit Function
    End If
    
    Next x
    
    IsPrime = ValPrime
    
    End Function



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

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