Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
avi avi is offline
external usenet poster
 
Posts: 195
Default The fastest way to count values in a range

Hello,

I'm writing an application that counts values in a large selection if
they comply to a crieria of greater than Firstvalue and smaller than
secondvalue .

The selection could be a huge Excel range, so that the speed is a very
important factor.

I use a procedure like:

For Each cell In Selection
If cell.Value <= secondvalue And cell.Value = Firstvalue
Then R = R + 1
Next cell

Is it the fastest way or are there better ones (Excel functions?)

All the data are numeric

Thanks a lot
Avi

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default The fastest way to count values in a range

=SUMPRODUCT(--(A1:A100<=secondvalue),--(A1:A100=firtsvalue))

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"avi" wrote in message
ups.com...
Hello,

I'm writing an application that counts values in a large selection if
they comply to a crieria of greater than Firstvalue and smaller than
secondvalue .

The selection could be a huge Excel range, so that the speed is a very
important factor.

I use a procedure like:

For Each cell In Selection
If cell.Value <= secondvalue And cell.Value = Firstvalue
Then R = R + 1
Next cell

Is it the fastest way or are there better ones (Excel functions?)

All the data are numeric

Thanks a lot
Avi



  #3   Report Post  
Posted to microsoft.public.excel.programming
avi avi is offline
external usenet poster
 
Posts: 195
Default The fastest way to count values in a range

Hi Bob,

Very fast and impressive, but frankly it's the first time i saw such a
formula. Usually I use SUMPRODUCT for a cross multiplication.

Could you expalin it a little bit so i can integrate it in my VBA
code ?

Thanks again
Avi

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default The fastest way to count values in a range

It's all explained at http://www.xldynamic.com/source/xld.SUMPRODUCT.html

If you want to use it in VBA, use

myVal =
Activesheet.Evaluate("SUMPRODUCT(--(A1:A100<=secondvalue),--(A1:A100=firstvalue))")

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"avi" wrote in message
oups.com...
Hi Bob,

Very fast and impressive, but frankly it's the first time i saw such a
formula. Usually I use SUMPRODUCT for a cross multiplication.

Could you expalin it a little bit so i can integrate it in my VBA
code ?

Thanks again
Avi



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
Count Max values in a range Brian Excel Worksheet Functions 6 September 20th 08 02:04 PM
Fastest way to select large range (e.g. B3:F1002)? [email protected] Excel Discussion (Misc queries) 7 August 31st 07 04:36 PM
What is the fastest way to copy a range to a 2D array? equiangular Excel Programming 10 February 12th 07 02:25 PM
fastest sorting routine for 2-D array of long values RB Smissaert Excel Programming 8 May 6th 06 05:06 PM
Count the how many different values in a range beechum1 Excel Worksheet Functions 3 February 12th 06 06:45 AM


All times are GMT +1. The time now is 12:06 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"