Thread: counting "="
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Keithlo Keithlo is offline
external usenet poster
 
Posts: 62
Default counting "="

I think it's because the = sign is not text but part of the formula.
Although I also can't get it to work when I make it text. However, this code
does work:

Dim Counter, c
Counter = 0
For Each c In Selection

If c.Formula Like "*=*" Then
Counter = Counter + 1
End If

Next c

MsgBox (Counter)

So VBA can handle it at least. My code assumes you select your range and
want output to a message box, but you could change it to be a pre-determined
range and put the result in a cell. I don't understand why the Excel
function doesn't work on an = sign as a string, but I am not surprised it
doesn't work when its part of a formula because then it's not part of the
value of the cell. And I know that Excel functions don't seem to have a
contains or like feature, which VBA does have.

Hope this helps.

Keith

"rockhammer" wrote:

Is there a way to make something like =countif($a$1:$a$100,"=") work as
intended?

The function is returning zero when there are clearly cells with the text
"=" in it. If i were to use something like $a:$a as the range, it will just
count all the blank cells in column A.

Thanks.