Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 82
Default how to calculate divisors of a number

Is there any command or macro to give the divisors of a number in
Excel?
  #2   Report Post  
Posted to microsoft.public.excel.misc
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

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 31
Default how to calculate divisors of a number

Rasoul,

a correction to the formula:
It must be a matrix formula, which means it shold be accepted with Ctrl+Shift+Enter,
so that the formula looks like
{=OR(A1=2,A1=3,AND(A1/ROW(INDIRECT("2:"&INT(SQRT(A1))))<INT(A1/ROW(INDIRECT("2:"&INT(SQRT(A1)))))))}

Sorry, Hans T.
_______________________________

"Hans Terkelsen" <dk wrote in message ...

"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

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 82
Default how to calculate divisors of a number

Dear Hans
Thanks for your solution. Let me check it and come here again if it is
necessary.
Sorry for late reply. I was expecting a notification in my email but
it seams whether it is not same here or I haven't set it.
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
How do I calculate the 3 sigma of a number? OGWONE Excel Worksheet Functions 1 May 17th 10 09:23 PM
formula to calculate the number Sasikiran Excel Discussion (Misc queries) 3 July 10th 09 03:05 PM
How to calculate number of occurencies of a specific number number Stefan Excel Discussion (Misc queries) 4 September 8th 08 08:33 AM
return in fractions with multiple divisors, linear rflock Excel Worksheet Functions 2 August 21st 07 01:43 AM
Calculate Number [email protected] Excel Discussion (Misc queries) 7 August 1st 07 03:56 PM


All times are GMT +1. The time now is 01:53 AM.

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

About Us

"It's about Microsoft Excel"