View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Hans Terkelsen Hans Terkelsen is offline
external usenet poster
 
Posts: 31
Default how to calculate divisors of a number


"Rasoul Khoshravan" wrote in message
...
Is there any command or macro to give the divisors of a number in
Excel?


Hi Rasoul.

A step in the right direction is this formula, which gives TRUE if A1 is a prime:
=OR(A1=2,A1=3,AND(A1/ROW(INDIRECT("2:"&INT(SQRT(A1))))<INT(A1/ROW(INDIRECT("2:"&INT(SQRT(A1)))))))

I don't know who to credit for the formula.

To find the divisors of A1, A2 ... maybe a sub like this:

DefDbl A-Z
Sub Primefactors()
Application.ScreenUpdating = False
While VarType(Selection) = 5
t = Selection
For f = 2 To Sqr(t)
While Int(t / f) = t / f
ActiveCell.Offset(0, 1).Select
Selection = f
t = t / f
Wend
If f Sqr(t) Then Exit For
Next
If t 1 Then
ActiveCell.Offset(0, 1).Select
Selection = t
End If
ActiveCell.Offset(1, 1 - ActiveCell.Column).Select
Wend
Application.ScreenUpdating = True
End Sub

HansT