PC Review


Reply
Thread Tools Rate Thread

Count non-zero cells

 
 
Otto Moehrbach
Guest
Posts: n/a
 
      12th Apr 2007
Excel XP & Win XP
I have a sheet with zero values suppressed (Tools - Options - View tab -
Uncheck Zero values).
I have a range, say F13:F16.
Each cell has a formula that produces a number.
The result in one cell is zero so that cell appears blank.
I want to count the number of non-zero cells in the range.
The worksheet formula:
CountIf(F13:F16,"<>0")
produces the correct answer, 3.
I need to do this in VBA so I use:
Range("H7").Value = Application.CountIf(Range("F13:F17"), "<>0")
This produces a 4.
What is the correct syntax to produce a 3?
Thanks for your time. Otto



 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWlrZQ==?=
Guest
Posts: n/a
 
      12th Apr 2007
You have different ranges in your formula (F13:F16) & (F13:F17)

using the same range in both I get the same answer.

Mike

"Otto Moehrbach" wrote:

> Excel XP & Win XP
> I have a sheet with zero values suppressed (Tools - Options - View tab -
> Uncheck Zero values).
> I have a range, say F13:F16.
> Each cell has a formula that produces a number.
> The result in one cell is zero so that cell appears blank.
> I want to count the number of non-zero cells in the range.
> The worksheet formula:
> CountIf(F13:F16,"<>0")
> produces the correct answer, 3.
> I need to do this in VBA so I use:
> Range("H7").Value = Application.CountIf(Range("F13:F17"), "<>0")
> This produces a 4.
> What is the correct syntax to produce a 3?
> Thanks for your time. Otto
>
>
>
>

 
Reply With Quote
 
Roger Govier
Guest
Posts: n/a
 
      12th Apr 2007
Hi Otto

Unless it was a typo when posting, you are looking at 2 different size
ranges
F13:F16 with formula
F13:F17 in code
This may well account for the different result.
--
Regards

Roger Govier


"Otto Moehrbach" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Excel XP & Win XP
> I have a sheet with zero values suppressed (Tools - Options - View
> tab - Uncheck Zero values).
> I have a range, say F13:F16.
> Each cell has a formula that produces a number.
> The result in one cell is zero so that cell appears blank.
> I want to count the number of non-zero cells in the range.
> The worksheet formula:
> CountIf(F13:F16,"<>0")
> produces the correct answer, 3.
> I need to do this in VBA so I use:
> Range("H7").Value = Application.CountIf(Range("F13:F17"), "<>0")
> This produces a 4.
> What is the correct syntax to produce a 3?
> Thanks for your time. Otto
>
>
>



 
Reply With Quote
 
Otto Moehrbach
Guest
Posts: n/a
 
      12th Apr 2007
Mike, Roger
You're absolutely right. A typo. Thanks. Otto
"Otto Moehrbach" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Excel XP & Win XP
> I have a sheet with zero values suppressed (Tools - Options - View tab -
> Uncheck Zero values).
> I have a range, say F13:F16.
> Each cell has a formula that produces a number.
> The result in one cell is zero so that cell appears blank.
> I want to count the number of non-zero cells in the range.
> The worksheet formula:
> CountIf(F13:F16,"<>0")
> produces the correct answer, 3.
> I need to do this in VBA so I use:
> Range("H7").Value = Application.CountIf(Range("F13:F17"), "<>0")
> This produces a 4.
> What is the correct syntax to produce a 3?
> Thanks for your time. Otto
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count contiguous cells, or count cell clusters BizoNo Microsoft Excel Worksheet Functions 0 16th Feb 2010 07:06 PM
Excel 2007. BUG. Count is defined as a long. Cells.Count results in error Overflow keepITcool Microsoft Excel Crashes 4 6th Jul 2006 10:14 PM
SUBTOTAL Second Count / sub-count of Filtered Visible Cells QTE Microsoft Excel Misc 13 4th Aug 2004 04:47 PM
SUBTOTAL Second Count / sub-count of Filtered Visible Cells QTE Microsoft Excel Worksheet Functions 0 27th Jul 2004 08:47 PM
SUBTOTAL Second Count / sub-count of Filtered Visible Cells QTE Microsoft Excel Worksheet Functions 3 21st Jul 2004 11:50 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:19 AM.