Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Counta anomaly

Hi all,
I'm trying to test whether both cellls in a pair are empty, I written
a macro and a function to do the same thing both use Counta and both
return different answers:
Macro (cell2 and cell3 are values taken from cells A5 and A6)
if WorksheetFunction.CountA(cell2, cell3) = 0 Then
answer= "Blank"
Else
answer= "not blank"
End if
returns :"not blank"

The Function
if(Counta(a5,a6)=0,"Blank","not blank")
returns :"blank"

The function is returning correctly. I have tried changing the
"transition navigation keys" setting but nothing changed. The VB
debugger says cell2 and cell3 are both Empty going into the test, why
is the macro returning wrong?


I am using Excel 97 and cannot work this out.

Any help would be appreciate

Thanks

Paul
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Counta anomaly

The key thing here is how you set the values of cell2 and cell3, and you
didn't post that code which you should have. But based on your description,
you're passing Counta the "value" of the cells rather than the cells
themselves. The value of empty cells is 0 for many purposes (e.g., enter
=A1 in a cell and it returns 0 even though A1 is empty) and 0 is not empty.

These examples illustrate what I think is going on. In both, A1 and A2 are
empty:

Sub Bad()
Dim Cell1Val As Variant
Dim Cell2Val As Variant
Cell1Val = Range("A1").Value
Cell2Val = Range("A2").Value
MsgBox Application.CountA(Cell1Val, Cell2Val) ''2
End Sub

Sub Good()
Dim Cell1Rg As Range
Dim Cell2Rg As Range
Set Cell1Rg = Range("A1")
Set Cell2Rg = Range("A2")
MsgBox Application.CountA(Cell1Rg, Cell2Rg) ''0
End Sub


--
Jim Rech
Excel MVP


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
Top N Pivot Anomaly PatK Excel Discussion (Misc queries) 0 April 10th 09 10:14 PM
Date anomaly HaoHoaMastercard Excel Discussion (Misc queries) 4 October 11th 07 08:05 PM
Sort anomaly supersheet Excel Worksheet Functions 0 August 28th 07 06:57 PM
VLOOKUP Anomaly Tosca Excel Worksheet Functions 6 May 8th 05 09:08 AM
COUNTA Function not working =COUNTA(C3:C69,"NH") MikeinNH Excel Worksheet Functions 2 November 8th 04 02:19 AM


All times are GMT +1. The time now is 12:21 PM.

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"