Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
 
Posts: n/a
Default An add-in that allows you to find the highest prime in a number

I am looking for an add-in that would allow you to find the highest
prime divisor in a number. ie 68, 2x2x17, so 17 is the highest prime.
Any help would be much appreciated...

  #2   Report Post  
Posted to microsoft.public.excel.misc
Bob Phillips
 
Posts: n/a
Default An add-in that allows you to find the highest prime in a number

Here is a function that I adapted from something I found in a Google

Function MaxPrime(limit As Long)
Dim PrimeCnt As Long
Dim y As Long
Dim x As Long
Dim Primes

ReDim Primes(1 To limit)
PrimeCnt = 1
If limit Mod 2 = 0 Then
Primes(PrimeCnt) = 2
PrimeCnt = PrimeCnt + 1
End If
If limit Mod 3 = 0 Then
Primes(PrimeCnt) = 3
PrimeCnt = PrimeCnt + 1
End If
x = 3
Do
x = x + 2
For y = 3 To Sqr(x) Step 2
If x Mod y = 0 Then GoTo noprime
Next y
If limit Mod x = 0 Then
Primes(PrimeCnt) = x
PrimeCnt = PrimeCnt + 1
End If

noprime:
Loop Until x limit

MaxPrime = Application.Max(Primes)

End Function


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

wrote in message
ups.com...
I am looking for an add-in that would allow you to find the highest
prime divisor in a number. ie 68, 2x2x17, so 17 is the highest prime.
Any help would be much appreciated...



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Determining the highest number in a row Jaydubs Excel Discussion (Misc queries) 1 December 7th 05 03:05 PM
to find number of days between 2 dates using vba code in excel sjayar Excel Discussion (Misc queries) 3 November 3rd 05 06:24 AM
Lookup Highest Number gregork Excel Discussion (Misc queries) 5 December 14th 04 04:17 PM
How to find highest, lowest and last cell in row? Sam Excel Discussion (Misc queries) 3 December 3rd 04 11:59 AM
How do I find the first value in a column less than a number? redeucer Excel Worksheet Functions 6 November 4th 04 09:59 PM


All times are GMT +1. The time now is 03:29 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"