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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Countif not working....

Status
Not open for further replies.

chipig

Technical User
Nov 8, 2007
205
CA
Can someone help me with this code. I want to count the number of word "VRAI" in a column located in another sheet.
It returns 0 when I run the debugger.
Here is my code (this code is in another sheet called telephonie):


Dim NUMBER_OF_VRAI As Double

Set myRange = Worksheets("Bottin RAW").Range("G2:G1000")
NUMBER_OF_VRAI = Application.WorksheetFunction.CountIf(myRange, "VRAI")

Am I missing something?
 
In the cells you are counting against, is VRAI the only text in the cells or can there be other text as well e.g.

cell text = "VRAI"

or

cell text = "Some Other Text VRAI"

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 



You cells must contain VRAI and ONLY VRAI. No leading or trailing spaces.

Your code DOES work!!

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Yes there are some FAUX also.There is no trailing space.
I have checked twice.I really don't know why it's not working.
 
VRAI is the french word for TRUE, and FAUX for FALSE.
I'd test for -1 ...
 
NUMBER_OF_VRAI = Application.WorksheetFunction.CountIf(myRange, -1)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 



BTW...

Just a minor detail, somewhat like arranging deck chairs on the sinking Titanic, but Double is not the datatype that you need for a COUNT. Use Integer or Long as the case may be.

Other than that, paste "VRAI" into a cell and try again. It would seem that you nave NO CELLS with VRAI and only VRAI.


Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 


in that case
Code:
NUMBER_OF_VRAI = Application.WorksheetFunction.CountIf(MyRange, VRAI)
without quotes

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Spreadsheet functions are localized, not VBA:
NUMBER_OF_VRAI = Application.WorksheetFunction.CountIf(MyRange, True)

And True=-1 ...
 


ahhhhhhh, that must be vrai!

Vola, y'all!

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
BINGO you got it PHV!It's working now.
Thanx a lot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top