#1   Report Post  
Zachary Turner
 
Posts: n/a
Default COUNTIF

I want to count all entries in a range which are bold. I wrote a
function IsBold() that works if I give it a single cell as an argument.
It either returns TRUE or FALSE. What doesn't work is when I try to
use this function on a range with the COUNTIF. My syntax was
=COUNTIF(A1:A100, IsBold())

Is my sntax wrong? Thanks

  #2   Report Post  
KL
 
Posts: n/a
Default

Hi Zachary,

The second argument in the COUNTIF function is looking for a cell value. So
in your case it looks for the cells in the range [A1:A100] which have the
value TRUE and (not suprisingly) doesn't find any. If your function accepts
range argument and works on multiple cells (i.e. returns an array of
TRUE/FALSE values for each cell evaluated) then as an alternative you could
use:

=SUMPRODUCT(--IsBold(A1:A100))

Regards,
KL

"Zachary Turner" wrote in message
ups.com...
I want to count all entries in a range which are bold. I wrote a
function IsBold() that works if I give it a single cell as an argument.
It either returns TRUE or FALSE. What doesn't work is when I try to
use this function on a range with the COUNTIF. My syntax was
=COUNTIF(A1:A100, IsBold())

Is my sntax wrong? Thanks



  #3   Report Post  
Dave Peterson
 
Posts: n/a
Default

My bet is that your =isbold() has to be changed to accept a range larger than
one cell.

Option Explicit
Function IsBold(rng As Range) As Variant

Dim myCell As Range
Dim myArr() As Variant
Dim iCol As Long
Dim iRow As Long

If rng.Cells.Count = 1 Then
IsBold = CBool(rng.Font.Bold = True)
ElseIf rng.Areas.Count 1 Then
IsBold = CVErr(xlErrRef)
Else
ReDim myArr(1 To rng.Rows.Count, 1 To rng.Columns.Count)
For iCol = 1 To rng.Columns.Count
For iRow = 1 To rng.Rows.Count
myArr(iRow, iCol) _
= CBool(rng.Cells(iRow, iCol).Font.Bold = True)
Next iRow
Next iCol
IsBold = myArr
End If

End Function

And your function needs to be changed to somthing like:
=SUMPRODUCT(--isbold(A1:A10),B1:B10)



Zachary Turner wrote:

I want to count all entries in a range which are bold. I wrote a
function IsBold() that works if I give it a single cell as an argument.
It either returns TRUE or FALSE. What doesn't work is when I try to
use this function on a range with the COUNTIF. My syntax was
=COUNTIF(A1:A100, IsBold())

Is my sntax wrong? Thanks


--

Dave Peterson
  #4   Report Post  
Dave Peterson
 
Posts: n/a
Default

Oops. I just KL's response and saw that you were using =countif(). I missed
that in the subject and twice in the text!

This function will work like KL suggests:

=sumproduct(--isbold(a1:a10))



Dave Peterson wrote:

My bet is that your =isbold() has to be changed to accept a range larger than
one cell.

Option Explicit
Function IsBold(rng As Range) As Variant

Dim myCell As Range
Dim myArr() As Variant
Dim iCol As Long
Dim iRow As Long

If rng.Cells.Count = 1 Then
IsBold = CBool(rng.Font.Bold = True)
ElseIf rng.Areas.Count 1 Then
IsBold = CVErr(xlErrRef)
Else
ReDim myArr(1 To rng.Rows.Count, 1 To rng.Columns.Count)
For iCol = 1 To rng.Columns.Count
For iRow = 1 To rng.Rows.Count
myArr(iRow, iCol) _
= CBool(rng.Cells(iRow, iCol).Font.Bold = True)
Next iRow
Next iCol
IsBold = myArr
End If

End Function

And your function needs to be changed to somthing like:
=SUMPRODUCT(--isbold(A1:A10),B1:B10)

Zachary Turner wrote:

I want to count all entries in a range which are bold. I wrote a
function IsBold() that works if I give it a single cell as an argument.
It either returns TRUE or FALSE. What doesn't work is when I try to
use this function on a range with the COUNTIF. My syntax was
=COUNTIF(A1:A100, IsBold())

Is my sntax wrong? Thanks


--

Dave Peterson


--

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 COMBINATION?? Heather Excel Worksheet Functions 1 April 26th 05 02:44 AM
Combining IF and COUNTIF based on two columns maxtrixx Excel Discussion (Misc queries) 5 March 31st 05 06:21 PM
COUNTIF in one colum then COUNTIF in another...??? JonnieP Excel Worksheet Functions 3 February 22nd 05 02:55 PM
Countif - Countif maswinney Excel Worksheet Functions 3 November 15th 04 11:06 PM
countif, again Liz G Excel Worksheet Functions 2 November 1st 04 11:20 PM


All times are GMT +1. The time now is 03:46 AM.

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"