PDA

View Full Version : Sleeper: Working on a range



lior03
07-25-2005, 09:37 AM
hello
i am looking for udf that will work on a range of integers.
starts with lowernumber up to highernumber
the function will return the number of integers that meet a certain criteria.
example-how many integers between lowrnumber to highernumber are even , how many are prime numbers?
my idea:


function xlinteger(lowernumber,highernumber)as integer
for i=lowernumber to highernumber
xlenteger=mod(i) 2 0
end function

as you see i got lost
any ideas?
thanks

Bob Phillips
07-25-2005, 10:18 AM
hello
i am looking for udf that will work on a range of integers.
starts with lowernumber up to highernumber
the function will return the number of integers that meet a certain criteria.
example-how many integers between lowrnumber to highernumber are even , how many are prime numbers?
my idea:


function xlinteger(lowernumber,highernumber)as integer
for i=lowernumber to highernumber
xlenteger=mod(i) 2 0
end function

as you see i got lost
any ideas?
thanks

We've already done primes!

You can do even numbers with a formula


=SUMPRODUCT(--(ISNUMBER(A1:A20)),--(A1:A20<>0),--(MOD(A1:A20,2 )=0))

lior03
07-25-2005, 10:30 AM
hello
i do not want a range of cells. i meant a range of integers for example from 20 to 30 or 100 to 150
is there a g eneral syntex to find how many integers met a certain criteria.
thanks

Bob Phillips
07-25-2005, 11:46 AM
hello
i do not want a range of cells. i meant a range of integers for example from 20 to 30 or 100 to 150
is there a g eneral syntex to find how many integers met a certain criteria.
thanks


=SUMPRODUCT(--(MOD(ROW(1:22),2 )=0))

adjus 1:22 to suit

lior03
07-28-2005, 05:31 AM
hello
to get how many even integers there are between two integers


Function tamar(first, last)
Dim t As Integer
Dim i As Integer
Dim cell As Range
t = 0
For i = first To last
If i Mod 2 = 0 Then
t = t + 1
tamar = t
End If
Next
End Function