Home |
Search |
Today's Posts |
#10
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Eric,
To find the next higher prime, use the UDF below (Copy the code and paste it into a codemodule) like this: =NextPrime(A2,TRUE) and to find the next lower prime, use it like this: =NextPrime(A2,FALSE) HTH, Bernie MS Excel MVP Option Explicit Function NextPrime(inRange As Long, Increase As Boolean) As Variant Dim i As Long Dim j As Long Dim boolSolved As Boolean Dim isPrime As Boolean boolSolved = False i = inRange While Not boolSolved i = i + IIf(Increase, 1, -1) If i < 2 Then NextPrime = "No prime is less than " & inRange Exit Function End If If i Mod 2 = 0 Then If i = 2 Then NextPrime = 2 Exit Function Else i = i + IIf(Increase, 1, -1) End If End If isPrime = True For j = 3 To i ^ 0.5 Step 2 If i Mod j = 0 Then isPrime = False End If Next j If isPrime Then NextPrime = i Exit Function End If Wend End Function "Eric" wrote in message ... Does anyone have any suggestions on how to determine the prime numbers? There is a given number 10 in cell A2, I would like to determine the next prime numbers below and over this given number 10. In this case, 11 will be returned in cell A1, and 7 will be returned in A3. Does anyone have any suggestions? Thanks in advance for any suggestions Eric |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How to determine the top 5 occurrences from a list of numbers? | Excel Discussion (Misc queries) | |||
How to determine the formula to generate following numbers? | Excel Discussion (Misc queries) | |||
How to determine the frequency of a list of numbers? | Excel Discussion (Misc queries) | |||
how to determine if a series of numbers contain odd or even values | Excel Worksheet Functions | |||
How do I determine which numbers in a list equal a given sum? | Excel Discussion (Misc queries) |