Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default why doesn't this countif work?

NumberOfTriples = WorksheetFunction.CountIf(Myrange, "???")
The above gives NumberOfTriples as 1 which is incorrect


For Each cell In MyRange
If Len(cell) = 3 Then NumberOfTriples = NumberOfTriples + 1
Next
This one gives NumberOfTriples as 4 which is correct


The ranges are simple 3x3 or 5x5 like A1:C3

thanks

John
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default why doesn't this countif work?


John,

What sort of data do you have in the range? COUNTIF(range,"???") will
only count text not numbers, if you want to count cells with 3
characters with a formula

=SUMPRODUCT(--(LEN(range)=3))


--
barry houdini
------------------------------------------------------------------------
barry houdini's Profile: http://www.thecodecage.com/forumz/member.php?userid=72
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=134051

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default why doesn't this countif work?

Its numbers as text. Working on sudoku solver so numbers stored as text,
at least I hope so. The cells are all formated as text and every
variable holding the data is a string variable. All string manipulations
seem to work fine such as mid, len, trim etc. when working with the cell
as a range. The Find function works with "???" but not the countif
function. However the countif works with "?". I have one range,
WholeThing, which is the entire sudoku.

If WorksheetFunction.CountIf(WholeThing, "?")=81 then the sudoku is
solved. And that works just fine.

It's not such a big deal cause there's other ways but it's just a mystery.


John


barry houdini wrote:
John,

What sort of data do you have in the range? COUNTIF(range,"???") will
only count text not numbers, if you want to count cells with 3
characters with a formula

=SUMPRODUCT(--(LEN(range)=3))


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default why doesn't this countif work?


You need to be careful when you format cells as text. If you enter a
number in a cell and then format as text afterwards then the cell format
will say text.....but it isn't. You can check by using ISTEXT worksheet
function.

Usually COUNTIF counts text and numbers so

=COUNTIF(A:A,1)

will count any cells in column A that contain a 1 whether it's text
formatted or not, but as soon as you introduce a wildcard, numbers
aren't included so

=COUNTIF(A:A,"1?")

won't count 12 (unless it's text-formatted) but will count 1x


--
barry houdini
------------------------------------------------------------------------
barry houdini's Profile: http://www.thecodecage.com/forumz/member.php?userid=72
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=134051

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default why doesn't this countif work?

If WorksheetFunction.CountIf(WholeThing, "?")=81 then the
sudoku is solved. And that works just fine.


Why not just use the CountA worksheet function? Assuming WholeThing is a Range...

If WorksheetFunction.CountA(WholeThing) = 81 Then

--
Rick (MVP - Excel)


"John" wrote in message ...
Its numbers as text. Working on sudoku solver so numbers stored as text,
at least I hope so. The cells are all formated as text and every
variable holding the data is a string variable. All string manipulations
seem to work fine such as mid, len, trim etc. when working with the cell
as a range. The Find function works with "???" but not the countif
function. However the countif works with "?". I have one range,
WholeThing, which is the entire sudoku.

If WorksheetFunction.CountIf(WholeThing, "?")=81 then the sudoku is
solved. And that works just fine.

It's not such a big deal cause there's other ways but it's just a mystery.


John


barry houdini wrote:
John,

What sort of data do you have in the range? COUNTIF(range,"???") will
only count text not numbers, if you want to count cells with 3
characters with a formula

=SUMPRODUCT(--(LEN(range)=3))




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default why doesn't this countif work?

In the help, it looks like it should work, but I couldn't get it to work just
in a worksheet. I did get this to work in the worksheet when entered as an
array function.

=COUNT(IF(LEN(D6:D13)=3,D6:D13))

You may want to try something like that.

HTH,
Barb Reinhardt

"John" wrote:

NumberOfTriples = WorksheetFunction.CountIf(Myrange, "???")
The above gives NumberOfTriples as 1 which is incorrect


For Each cell In MyRange
If Len(cell) = 3 Then NumberOfTriples = NumberOfTriples + 1
Next
This one gives NumberOfTriples as 4 which is correct


The ranges are simple 3x3 or 5x5 like A1:C3

thanks

John

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default why doesn't this countif work?

That's more or less what I'm doing. It's just a mystery why countif
won't work. It works with a single "?".

Barb Reinhardt wrote:
In the help, it looks like it should work, but I couldn't get it to work just
in a worksheet. I did get this to work in the worksheet when entered as an
array function.

=COUNT(IF(LEN(D6:D13)=3,D6:D13))

You may want to try something like that.

HTH,
Barb Reinhardt

"John" wrote:

NumberOfTriples = WorksheetFunction.CountIf(Myrange, "???")
The above gives NumberOfTriples as 1 which is incorrect


For Each cell In MyRange
If Len(cell) = 3 Then NumberOfTriples = NumberOfTriples + 1
Next
This one gives NumberOfTriples as 4 which is correct


The ranges are simple 3x3 or 5x5 like A1:C3

thanks

John

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 174
Default why doesn't this countif work?

Hi John,

Take a look to Dermot Balson's page.

http://www.westnet.net.au/balson/Mod...werTools.shtml

Link - Sudoku -a workbook to solve it, give hints, even create new puzzles
of varying difficulty

Wkr,

JP

"John" wrote in message
...
That's more or less what I'm doing. It's just a mystery why countif won't
work. It works with a single "?".

Barb Reinhardt wrote:
In the help, it looks like it should work, but I couldn't get it to work
just in a worksheet. I did get this to work in the worksheet when
entered as an array function.

=COUNT(IF(LEN(D6:D13)=3,D6:D13))

You may want to try something like that.

HTH,
Barb Reinhardt

"John" wrote:

NumberOfTriples = WorksheetFunction.CountIf(Myrange, "???")
The above gives NumberOfTriples as 1 which is incorrect


For Each cell In MyRange
If Len(cell) = 3 Then NumberOfTriples = NumberOfTriples + 1
Next
This one gives NumberOfTriples as 4 which is correct


The ranges are simple 3x3 or 5x5 like A1:C3

thanks

John



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default why doesn't this countif work?

I'd check the data first and also make sure that that variable was 0 when I
started.

Maybe you have leading/trailing spaces in one of your cells

if len(cell.value) = len(trim(cell.value)) then
'ok
else
msgbox cell.address & " has an extra space!"
end if

NumberOfTriples = 0
for each cell in myrng.cells
...

John wrote:

NumberOfTriples = WorksheetFunction.CountIf(Myrange, "???")
The above gives NumberOfTriples as 1 which is incorrect

For Each cell In MyRange
If Len(cell) = 3 Then NumberOfTriples = NumberOfTriples + 1
Next
This one gives NumberOfTriples as 4 which is correct

The ranges are simple 3x3 or 5x5 like A1:C3

thanks

John


--

Dave Peterson
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
COUNTIF doesn't work KenH Excel Discussion (Misc queries) 12 October 13th 09 03:52 PM
Will countif work? Neall Excel Programming 6 October 25th 07 06:02 PM
How to get Countif to work this out? Wind54Surfer Excel Worksheet Functions 3 September 16th 07 03:06 AM
Countif does not work c4ec Excel Worksheet Functions 2 February 23rd 07 03:56 PM
countif(a1:a12,">TODAY()") How do I get this to work? Dan Bork Excel Worksheet Functions 1 November 11th 04 10:54 PM


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