Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Logic Question 3

Status
Not open for further replies.

souprog

Technical User
Aug 3, 2001
9
AU
I'm trying to do the following:

countif(range,&quot;>1 and <100&quot;)

but it won't let me use two criteria joined by an and. i've tried to find a between criteria function similar to the one in access but it doesn;t seem to exist.

any suggestions????


souprog
 
souprog,

Especially because you are comparing Excel to Access, you should give some attention to Excel's &quot;database&quot; functions.

Indeed, Excel's &quot;DCOUNT&quot; database function will DEFINITELY work for you. The following is an example:
=DCOUNT(data,1,crit)

You'll notice it's made up of 3 arguments:

The 1st argument is a reference to the range where you have your data located. The range can be 1 - 256 columns and up to 65,535 rows.

The 2nd argument refers to the column in your database from which you want to COUNT the number of records that match your criteria. The first column is 1, the second is 2, etc.

The 3rd argument is a reference to the range where you have your &quot;criteria&quot; located.

In this example... =DCOUNT(data,1,crit) ...I have used &quot;Range Names&quot;. Please NOTE: The use of Range Names is HIGHLY recommended for basically ALL uses of Excel. This is because &quot;internally&quot; Excel keeps track of the cell coordinates of Range Names, therefore making it much easier to insert rows and columns without concern for affecting, for example, VBA code which would otherwise have to be changed if the VBA was written with &quot;hard-coded&quot; cell coordinates.

Creating Range Names is real easy. Take these steps:
1) Highlight the range you wish to name
2) Use <Control> <F3> (Hold down <Control> and hit <F3>
3) Type the name
4) Hit <Enter>

An alternative to step #2, is to click on the &quot;Name Box&quot; which is the box immediately above the &quot;A&quot; of the 1st column.

A final point about Range Names: Do NOT use names which will conflict with Excel's cell coordinates or with numbers. For example, don't use a name like &quot;A14&quot; - instead use &quot;A_14&quot;. Don't use a number like &quot;23&quot; - instead use &quot;_23&quot;.

TESTING OUT THE FORMULA:

You might want to first test the DCOUNT formula on a separate worksheet, by taking the following steps:

1) In cell &quot;A5&quot;, enter the text &quot;colm1&quot;. This will be a &quot;field name&quot; for the first column of your database. In this case, we'll only use the one column, but the database could be set up with several fields.

2) With the cursor on &quot;A5&quot;, hold down the &quot;SHIFT&quot; key and the &quot;Page-Down&quot; key until you've highlighted a sizeable number of rows.

3) Use <Control> <F3> (or click on the &quot;Name Box&quot;)

4) Type the name &quot;data&quot;, and hit <Enter>.

5) Copy the field name from cell &quot;A5&quot; to cell &quot;D1&quot; and cell &quot;E1&quot;.

6) In cell &quot;D2&quot;, type: >1

7) In cell &quot;E2&quot;, type: <100

8) Place the cursor on cell &quot;D1&quot; and highlight the range &quot;D1:E2&quot;.

9) Assign the Range Name &quot;crit&quot; to this range.

10) In cell &quot;C1&quot;, enter the text &quot;crit1&quot;. This will later serve as a reference for you - to know that the &quot;criteria&quot; range to the right is named &quot;crit&quot;. With a large application, you might end up having SEVERAL separate &quot;criteria&quot;, so it will be important to properly label each one.

11) You're now ready to enter the DCOUNT formula, and you could enter it anywhere - EXCEPT of course NOT within the range &quot;data&quot;. For now, enter the formula into cell &quot;A1&quot;, by simply typing: =DCOUNT(data,1,crit) and <Enter>.

Now test the formula by going to any cell within your defined database (the range named &quot;data&quot; - starting at cell &quot;A6&quot;) - and enter numbers &quot;within&quot; the range of your criteria 2 - 99, and &quot;outside&quot; your criteria - <2 or >99.

And of course you'll notice that your formula in cell &quot;A1&quot; will ONLY count those numbers >1 and <100.

I hope you've found this a good &quot;introduction&quot; to the world of &quot;Excel database formulas&quot;, and I trust it will resolve your immediate problem.

Please advise as to how you make out.

Regards, ...Dale Watson dwatson@bsi.gov.mb.ca
 
Dale,

I've given then named range of criteria a go, but it still doesn;t seem to work. Through some further testing it works if i only specify one criteria - as soon as i add the second criteria (the top limit) the answer returned is zero.

Thanks for your help.

souprog
 
souprog,

I just realized you replied right away. If you are still there, why not email me - at my HOME address, and I'll email you the file I created specifically for your situation. It DEFINITELY works.

Regards, ...Dale Watson HOME: nd.watson@shaw.ca
 
souprog,

It seems I missed you.

Email me at work tomorrow morning, and I'll send the file via return email.

Once you see the example file, you'll see how &quot;easy&quot; it really is. And I can send other example database files later if you wish.

Regards, ...Dale Watson
WORK: dwatson@bsi.gov.mb.ca
HOME: nd.watson@shaw.ca

 
souprog,

I'm curious to know how you have made out !!!

Please provide an update.

Thanks.

Regards, ...Dale Watson
 
souprog,

I hope that you will recognize Dale for his fine and detailed response to your questions as both helpful and expert. I certainly found them to be so.

Consequently...
Code:
   With Contributor
      .Post = vbHelpfulExpert    (:I
      .Recognition = vbSTAR    *:->*
  End With
LOL Skip,
metzgsk@voughtaircraft.com
 
Skip,

VERY &quot;cute&quot; !!!

...THANKS for confirming that it works - and &quot;meets with your (esteemed) approval&quot; ...and THANKS for the STAR.

...Dale :)
 
Dale

I got it to work!! (I wasn't including the column names in the data ranges).

I have also come accross another solution for my original problem:

=sum((data>1)*(data<=100)) Control-Shift-Enter (to make it an array)

seems to also work...

Thanks for your help

Souprog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top