PC Review


Reply
Thread Tools Rate Thread

how to calculate divisors of a number

 
 
Rasoul Khoshravan
Guest
Posts: n/a
 
      25th Jul 2011
Is there any command or macro to give the divisors of a number in
Excel?
 
Reply With Quote
 
 
 
 
Hans Terkelsen
Guest
Posts: n/a
 
      26th Jul 2011

"Rasoul Khoshravan" <(E-Mail Removed)> wrote in message
news:71068d3d-7568-4c04-af2b-(E-Mail Removed)...
> 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

 
Reply With Quote
 
Hans Terkelsen
Guest
Posts: n/a
 
      26th Jul 2011
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 news:4e2eab61$0$313$(E-Mail Removed)...
>
> "Rasoul Khoshravan" <(E-Mail Removed)> wrote in message
> news:71068d3d-7568-4c04-af2b-(E-Mail Removed)...
>> 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
>

 
Reply With Quote
 
Rasoul Khoshravan
Guest
Posts: n/a
 
      28th Aug 2011
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to calculate number of occurencies of a specific number number Stefan Microsoft Excel Misc 4 8th Sep 2008 08:33 AM
Finding all divisors of given number in a set Mac Microsoft Excel Programming 2 18th Mar 2008 04:34 PM
return in fractions with multiple divisors, linear =?Utf-8?B?cmZsb2Nr?= Microsoft Excel Worksheet Functions 2 21st Aug 2007 01:43 AM
Calculate Number yolanda.silva@gmail.com Microsoft Excel Misc 7 1st Aug 2007 03:56 PM
Calculate a number using a specified date and another number =?Utf-8?B?QmVydA==?= Microsoft Access Queries 1 20th Mar 2006 04:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:35 PM.