LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default CountA and Countif and Arrays

Clif McIrvin wrote on 6/29/2011 :
"GS" wrote in message ...
Tim Childs wrote :
Hi

I found out the hard way (by searching the internet/newsgroups) that while
it
is possible to use the Count worksheet function with a declared array, as
follows:
iNewRowsRequired = WorksheetFunction.CountA(ColumnsInfo)

BUT it is not possible to use it with CountIf worksheet function.

Can someone help show me where I can find that Countif will not work with
declared arrays?

Many thanks

Tim


This returns the number of cells that contain the value 4 in row3:

Debug.Print Application.WorksheetFunction.CountIf([3:3], 4)



Which doesn't answer OP's question. I was unable to learn anything other
than to verify that Countif doesn't work with declared arrays, but that Count
does:


That is what the online help says! Not sure why anyone would expect
something other than that!

The solution is obvious to me:

If you need to use CountIf in code then pass it a range object and
criteria.

If you need to use CountA in code then pass it a range object OR an
array of values.

If you need to use both on the same data source, pass them both a
range object.


Option Explicit

Sub x()
Dim a, b, c


Set a = Range("A1:A17")
b = WorksheetFunction.CountA(a) '//ACCEPTS a range OR an array.

c = WorksheetFunction.CountIf(a, "???") '//REQUIRES range,criteria


Stop
End Sub


--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc




 
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
COUNTA or COUNTIF?? Jayme Excel Discussion (Misc queries) 7 September 4th 09 12:52 AM
If with countif or counta [email protected] Excel Worksheet Functions 3 September 28th 08 07:24 PM
Counta with CountIf [email protected] Excel Programming 3 December 20th 07 05:28 PM
CountIF, CountA,Which one? or neither? amy Excel Discussion (Misc queries) 2 July 20th 05 07:09 PM
COUNTA, COUNTIF? Newbie Excel Worksheet Functions 1 March 18th 05 11:33 AM


All times are GMT +1. The time now is 09:29 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"