Solved

Excel - formula

Posted on 2011-09-21
8
195 Views
Last Modified: 2012-05-12
My OS is windows 7 and I am using Excel 2007.  I would like to know how to achieve this :

Say in Col A, I have 20800. and in Col B 20898 and the numbers are to be Even.
I would like to find out what formula to use, say in Col C,  to get all the even numbers from 20800 to 20898, just a count only of how many even numbers are in that range..  

Another problem is , say in Col A the number is 20801 and in Col B 20899 and the numbers are to Odd.  I would like to find out the same time of formula as above, but for Odd numbers, and again a count only of all the ODD numbers in this range. .

As I have more numbers to run thus to see if I can do it the smart way. thank u.
0
Comment
Question by:jegajothy
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 50

Assisted Solution

by:barry houdini
barry houdini earned 250 total points
ID: 36575602
If both numbers are even then the number of even numbers in that range can be given by

=(B2-A2)/2+1

same formula if they are both odd. Can one be even and the other odd?

This should work generically for any combination

=CEILING((B2-A2+1)/2,1)

regards, barry
0
 
LVL 12

Expert Comment

by:kgerb
ID: 36575603
I think this will work for both even and odd numbers

=ROUNDDOWN((B17-A17)/2-1,0)
0
 
LVL 12

Expert Comment

by:kgerb
ID: 36575627
Barry,
I tried your second formula and between the numbers 20 and 24 it says there are 3 even numbers?  Am I not understanding the questions correctly?
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 27

Expert Comment

by:Glenn Ray
ID: 36575633
If you want to know the number of even or odd numbers there are WITHIN the range:
=((B1-A1)/2)-1
This total will not include the starting and ending numbers in the count.  If you want to count them also:
=((B1-A1)/2)+1

Same formula applies regardless of odd or even numbers.  Why?  Because the difference of two odd numbers is always an even number, hence you can divide it by two to get an answer.


0
 
LVL 22

Accepted Solution

by:
rspahitz earned 250 total points
ID: 36575646
count of even numbers:

=INT((B1-A1)/2)+IF(EVEN(A1),1,0)

count of odd numbers:

=INT((B1-A1)/2)+IF(ODD(A1),1,0)
0
 
LVL 50

Expert Comment

by:barry houdini
ID: 36576298
Looks like we're all answering slightly different questions.....!

My interpretation was that you would count inclusive - including the start and end numbers - but my suggested formula didn't work even for that.

kgerb, your formula counts excluding start and end numbers....and it works if both are odd or both even......and I think Glenn's does the same.

rspahitz, I think you are trying to do what I wanted to do with my second formula, count even or odd numbers whatever the start or end numbers.....I don't think it works, though. for 4 and 8 I get 3 with the odd number formula - shouldn't that be 2?

I go for this one for even

=INT((B2-A2+MOD(A2+1,2)+1)/2)

and this for odd

=INT((B2-A2+MOD(A2,2)+1)/2)

regards, barry

0
 

Author Closing Comment

by:jegajothy
ID: 36576303
Thank u everyone for your responses.  So many ways to skin a cat! Thank u
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 36576813
Thanks jj, yes, many ways to handle this.

Barry, "for 4 and 8 I get 3 with the odd number formula - shouldn't that be 2?"
If I got it right, my formula searching for ODD takes 8-4 (4) divides it by 2 (2) and adds 1 only if the first number is odd (which it isn't so add 0) and leaves it at 2, which seems to be correct since the correct numbers are 5 and 7.

This turned out to be more difficult than it appeared at first.  Thanks for the brain-teaser.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question